【问题标题】:Still waiting for db to be ready... Or maybe the db is not reachable. 59 attempts leftStill waiting for db to be ready... Or maybe the db is not reachable. 59 attempts left
【发布时间】:2022-11-20 11:47:33
【问题描述】:

docker-compose.yml

version: "3.4"

services:
  php:
    build:
      context: .
      target: symfony_php
      args:
        SYMFONY_VERSION: ${SYMFONY_VERSION:-}
        SKELETON: ${SKELETON:-symfony/skeleton}
        STABILITY: ${STABILITY:-stable}
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s
    environment:
      # Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
      DATABASE_URL: mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@gk_app:3567/${MYSQL_DB:-gk_app}?serverVersion=13&charset=utf8
      # Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
      MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
      MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
      MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}

  caddy:
    build:
      context: .
      target: symfony_caddy
    depends_on:
      - php
    environment:
      SERVER_NAME: ${SERVER_NAME:-localhost, caddy:80}
      MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}
      MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
      - caddy_data:/data
      - caddy_config:/config
    ports:
      # HTTP
      - target: 80
        published: ${HTTP_PORT:-80}
        protocol: tcp
      # HTTPS
      - target: 443
        published: ${HTTPS_PORT:-443}
        protocol: tcp
      # HTTP/3
      - target: 443
        published: ${HTTP3_PORT:-443}
        protocol: udp

# Mercure is installed as a Caddy module, prevent the Flex recipe from installing another service
###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###

###> doctrine/doctrine-bundle ###
  database:
    image: mysql:8.0
    environment:
      MYSQL_DB: ${MYSQL_DB:-gk_app}
      # You should definitely change the password in production
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password}
      MYSQL_ALLOW_EMPTY_PASSWORD: "true"
    volumes:
      - db-data:/var/lib/mysql
      # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
      # - ./docker/db/data:/var/lib/postgresql/data:rw
###< doctrine/doctrine-bundle ###

volumes:
  php_socket:
  caddy_data:
  caddy_config:
###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###

###> doctrine/doctrine-bundle ###
  db-data:
###< doctrine/doctrine-bundle ###

docker-compose.override.yml

version: "3.4"

# Development environment override
services:
  php:
    volumes:
      # The "cached" option has no effect on Linux but improves performance on Mac
      - ./:/srv/app:rw,cached
      - ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini
      # If you develop on Mac you can remove the var/ directory from the bind-mount
      # for better performance by enabling the next line
      - ./var/storage:/srv/app/var/storage:rw
    environment:
      APP_ENV: dev

  caddy:
    volumes:
      - ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - ./public:/srv/app/public:ro

###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###

###> doctrine/doctrine-bundle ###
  database:
    ports:
      - "3567:3306"
###< doctrine/doctrine-bundle ###

###> blackfireio/blackfire-symfony-meta ###
  blackfire:
    image: blackfire/blackfire:2
    # uncomment to store Blackfire credentials in a local .env.local file
    #env_file: .env.local
    environment:
      BLACKFIRE_LOG_LEVEL: 4
    ports: [8307]
###< blackfireio/blackfire-symfony-meta ###

###> symfony/mailer ###
  mailer:
    image: schickling/mailcatcher
    ports: [1025, 1080]
###< symfony/mailer ###

I run:- HTTP_PORT=8080 HTTPS_PORT=8443 SERVER_NAME=foo.localhost docker-compose up and get the error above with it counting down to zero. The containers/services fail to launch?

docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

I've tried DATABASE_URL: mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@gk_app:3567/${MYSQL_DB:-gk_app}?serverVersion=13&amp;charset=utf8 with different ports: 3567 & 3306 with no success?

Is anyone savvy with https://github.com/dunglas/symfony-docker/blob/main/docker-compose.yml and swapping postgres for mysql?

Edit: Trying:- DATABASE_URL: mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@localhost:3567/${MYSQL_DB:-gk_app}?serverVersion=13&amp;charset=utf8,

DATABASE_URL: mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@127.0.0.1:3567/${MYSQL_DB:-gk_app}?serverVersion=13&amp;charset=utf8

& DATABASE_URL: mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@database:3567/${MYSQL_DB:-gk_app}?serverVersion=13&amp;charset=utf8

all of these produce the same error?

【问题讨论】:

  • No service depends_on the database, so I don't see why it would fail with that error message. But anyways, in the envvar DATABASE_URL you define gk_app as the database host, but no service goes by that name. Is it an entry on your /etc/hosts or reacheable any other way? If not, try adding container_name: gk_app to the database: section.
  • Oh, I overlooked the port configuration. The database port exposed to the internal network is still 3306, so you should use mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@database:3306/${MYSQL_DB:-gk_app}?serverVersion=8.0&amp;charset=utf8. localhost would refer to the container running the php service. You can use the 3567 to access the database using localhostfrom the host computer(i.e. the "real" one")
  • OK, so with: DATABASE_URL: mysql://${MYSQL_USER:-root}:${MYSQL_PASSWORD:-password}@database:3306/${MYSQL_DB:-gk_app}?serverVersion=13&amp;charset=utf8 I still receive the error?

标签: docker symfony doctrine


【解决方案1】:

Make sure the DATABASE_URL is checked without cmets: https://github.com/dunglas/symfony-docker/pull/107

【讨论】:

    猜你喜欢
    • 2022-11-16
    • 2013-06-10
    • 2018-12-31
    • 2022-12-02
    • 1970-01-01
    • 2019-03-22
    • 2022-12-27
    • 1970-01-01
    • 2017-04-12
    相关资源
    最近更新 更多