Home > Enterprise >  load fixture using symfony and docker
load fixture using symfony and docker

Time:12-13

I'm creating web application using symfony, also I use docker in my project. I want to load fixture php bin/console doctrine:fixture:load, but I get this error

  An exception occurred in the driver: SQLSTATE[08006] [7] could not translate host name "my_els_db_postgres" to address: Temporary failure in name resolution  

docker-compose.yml:

services:
  database:
    container_name: my_els_db_postgres
    image: postgres:${POSTGRES_VERSION:-13}-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-app_my_ELS}
      # You should definitely change the password in production
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ChangeMe}
      POSTGRES_USER: ${POSTGRES_USER:-symfony}
    volumes:
      - db-data:/var/lib/postgresql/data:rw

.env:

DATABASE_URL="postgresql://symfony:ChangeMe@my_els_db_postgres:5432/app_my_ELS?serverVersion=13&charset=utf8"

How can I fix the problem. Thanks

CodePudding user response:

If I understand it correctly you are using postgres from docker-compose but symfony/php from local installation? If that is the case there is no way for your local php to know that my_els_db_postgres hostname is docker container.
You can test if with ping my_els_db_postgres.
To solve this you will want to add postgres container IP address to your hosts file (and probably set static IP for it).

Otherwise if your php is also running from container please update the question with it's docker-compose configuration.

CodePudding user response:

Use service name instead of container name.

DATABASE_URL="postgresql://symfony:ChangeMe@database:5432/app_my_ELS?serverVersion=13&charset=utf8"

  • Related