1

I'm using docker to develop a symfony project and I'm having a problem with mysql. Here is my configuration in my .env symfony:

DATABASE_URL=mysql://bpp:[email protected]:3306/bdd

when i run the php bin / console command d: s: u --force the database is well updated. By cons when I want to register a form I have a symfony connection error

error sf4

Here is my config docker:

version: '3.7'
services:
  apache:
    build: .docker/apache
    container_name: bpp_apache
    ports:
      - "80:80"
    volumes:
      - .docker/config/vhosts:/etc/apache2/sites-enabled
      - ${SYMFONY_APP}:/home/wwwroot/bpp
    depends_on:
      - php
  mysql:
    image: mysql:8
    container_name: bpp_mysql
    volumes:
      - ./.docker/data/db:/var/lib/mysql
    command:
      - "--default-authentication-plugin=mysql_native_password"
      - "--lower_case_table_names=1"
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    ports:
      - "3306:3306"
  php:
    build: .docker/php
    container_name: bpp_php
    volumes:
      - ${SYMFONY_APP}:/home/wwwroot/bpp
    depends_on:
      - mysql
    links:
      - mysql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: bpp_phpmyadmin
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
    ports:
      - "8080:80"

Thank you for help.

1

1 Answer 1

1

Change the .env configuration for mysql url from

DATABASE_URL=mysql://bpp:[email protected]:3306/bdd

to

DATABASE_URL=mysql://bpp:bpp@mysql:3306/bdd

The reason lies under docker itself. You are connecting two services: PHP and MySql which are running on different IP address inside docker network. Every time you run the docker file, you are starting 3 containers:

  1. Apache - IP Address 1
  2. PHP - IP address 2
  3. MySql - IP address 3

And MySql service is not on address 127.0.0.1. Leave this to the integrated DNS server.

Sign up to request clarification or add additional context in comments.

6 Comments

with DATABASE_URL = mysql: // bpp: bpp @ mysql: 3306 / bdd it works but against the php bin / console command d: s: u --force does not work anymore
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: H�te inconnu.
It seems to me that everything is fine with the URL. Try writing it again manually, maybe there is a non UTF character in the string.
Hmm try with "bpp_mysql" instead of "mysql" or just remove the container name from docker-file
same problem with bpp_mysql or remove container name
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.