I'm not good at creating docker-compose and am currently having trouble trying to build a new project.
After building, I cannot access the mariadb server in the php application container, I get this error:
PDO::__construct(): php_network_getaddresses: getaddrinfo of mariadb Failure: Name cannot be resolved
So I know something is misconfigured, but I don't know what yet. I tried many changes but nothing worked.
This is my current docker-compose.yml:
version: "3.8" networks: # used by some services (php) to communicate with other docker-compose.yaml censored.com: external: name: censored.com services: app: build: context: . target: symfony_php args: - secret=id=composerauth,src=${HOME}/.composer/auth.json restart: unless-stopped healthcheck: interval: 10s timeout: 3s retries: 3 start_period: 30s environment: APP_ENV: dev HOST: www.censored.lan networks: - default - censored.com volumes: - ./:/srv/app:rw,cached - ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini - ${HOME}/.composer/auth.json:/root/.composer/auth.json # If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host - ./var/cache:/srv/app/cache:rw - ./var/log:/srv/app/logs:rw depends_on: - mariadb extra_hosts: - www.censored.lan:127.0.0.1 nginx: build: context: . target: symfony_nginx args: - secret=id=composerauth,src=${HOME}/.composer/auth.json restart: unless-stopped depends_on: - app environment: NGINX_DOMAIN: www.censored.lan ports: - 8001:80 volumes: - ./docker/nginx/templates/dev.conf.template:/etc/nginx/templates/default.conf.template:ro - ./docker/nginx/rules/rules.dev.conf:/etc/nginx/rules.conf:ro - ./public:/srv/app/public:ro - ./src:/srv/app/src:ro mariadb: image: mariadb:10.7 environment: MYSQL_ROOT_PASSWORD: changeme MYSQL_DATABASE: database MYSQL_USER: user MYSQL_PASSWORD: changeme networks: - default - censored.com ports: - '3307:3306' restart: on-failure volumes: - db_data:/var/lib/mysql volumes: db_data: {}
Can someone help me solve this problem?
Thanks!
The problem has nothing to do with my docker-compose configuration file.
My application is a PHP Symfony application that does a "cache: clear" after the initial "composer install" during the build. "cache:clear" is triggering a call to a database that is not yet ready. To fix this, I simply set my mariadb version to the "DATABASE_URL" parameter in my Symfony application to avoid useless database queries.