Symfony docker container don’t manage to connect to mariadb container

I’m using docker to run :

  • Symfony image
  • MariaDB image

Here is my docker-compose.yaml file :

version: '2'
services:
  myapp:
    image: 'bitnami/symfony:1'
    ports:
      - '8000:8000'
    volumes:
      - '.:/app'
    environment:
      - SYMFONY_PROJECT_NAME=backend
      - MARIADB_HOST=mariadb
      - MARIADB_PORT_NUMBER=3306
      - MARIADB_USER=monty
      - MARIADB_PASSWORD=monty
      - MARIADB_DATABASE=test
    container_name: symfony_container
    depends_on:
      - mariadb
  mariadb:
    image: 'bitnami/mariadb:10.3'
    ports:
      - '3306:3306'
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
      - MARIADB_DATABASE=test
      - MARIADB_PORT_NUMBER=3306
      - MARIADB_ROOT_USER=root
    container_name: mariadb

I start both containers with the command :

docker-compose up

That generates a “backend” directory, representing the Symfony install.

In that directory, I manage to create an entity with:

php bin/console make:entity

but then, when I run the command:

php bin/console make:migration

I get the following errors :

An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution 

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution    

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution 

I guess the error might come from some of the user parameters.

Yet when I run the command

docker-compose exec mariadb mysql -u monty -p 

and enter the password “monty”, I manage to access my database, so I don’t quite understand why my symfony container could not.

If I enter the symfony container with command :

docker exec -it symfony_container bash

This command works:

php bin/console make:entity

But the command

php bin/console make:migration

return the following errors:

An exception occurred in driver: SQLSTATE[HY000] [1049] Unknown database 'bitnami_myapp' 

SQLSTATE[HY000] [1049] Unknown database 'bitnami_myapp'

SQLSTATE[HY000] [1049] Unknown database 'bitnami_myapp'

I edited the docker-compose.yml file located at “/app” inside the Symfony container, and it has the exact same pieces of information as the docker-compose.yml file above.

Thanks for the reply!

UPDATE :

Abdennour Toumi answer solve a part of my issue, thanks!

The other part regarding the ‘bitnami_myapp’ unknown database came from the .env.local file, that still had default database in parameter.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *