Database connection issue through docker containers

I have set up a dev environment with Symfony and MariaDB through docker.

I’ve taken the bitman/symfony image there :

 https://hub.docker.com/r/bitnami/symfony

This is my docker-compose.yaml

version: '2'

services:
  myapp:
    image: 'bitnami/symfony:1'
    ports:
      - '8000:8000'
    volumes:
      - '.:/app'
    environment:
      - SYMFONY_PROJECT_NAME=backend
      - MARIADB_PORT_NUMBER=3306
      - MARIADB_USER=root
    container_name: symfony_container
    depends_on:
      - mariadb
  mariadb:
    image: 'bitnami/mariadb:10.3'
    ports:
      - '3306:3306'
  environment:
    - ALLOW_EMPTY_PASSWORD=yes
    - MARIADB_USER=root
  container_name: mariadb_container

Important line in .env file :

DATABASE_URL=mysql://root:@localhost:3306/

My doctrine.yaml file:

doctrine:
  dbal:
      url: '%env(resolve:DATABASE_URL)%'
      server_version: '5.7'
  orm:
      auto_generate_proxy_classes: true
      naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
      auto_mapping: true
      mappings:
          App:
              is_bundle: false
              type: annotation
              dir: '%kernel.project_dir%/src/Entity'
              prefix: 'AppEntity'
              alias: App

Now if I run docker-compose up, both containers start and I can access Symfony.

BUT if I try to create an entity with :

php bin/console make:entity

I get the four 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 

The strange thing is that I can access MariaDB database through dbeaver without trouble. It seems as if the Symfony container did not manage to find the MariaDB container.

I’ll precise that I use symfony version 5.0.4

If anyone knows where those errors come from I’ll be grateful

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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