I've got my dev environment running in docker (nginx, php and mariadb) and try to create a database in symfony with doctrine. When I run php bin/console doctrine:database:create , I will get the following error:
[critical] Error thrown while running command "doctrine:database:create". Message: "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution"
My configuration in .env looks like this:
DATABASE_URL="mysql://admin:symfony-admin@db/symfony_test?serverVersion=mariadb-10.1"
And this is my docker-compose.yml:
version: "3.6"
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
depends_on:
- php
php:
build: .
volumes:
- ./code:/code
links:
- db
db:
image: mariadb:latest
restart: always
ports:
- "33006:3306"
volumes:
- ./db:/docker-entrypoint-initdb.d/
environment:
MYSQL_ROOT_PASSWORD: 'symfony-root-pwd'
MYSQL_DATABASE: 'symfony_db'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'symfony-admin'
I also use adminer to have access to the database and there the login works.
Does someone know why I can't create a database with doctrine?
Cheers,
Michael
Solution:
I found the solution by myself. The command php bin/console doctrine:database:create need to be run within the php docker container and not in the local terminal.
So at first docker-compose exec php /bin/bash and then php bin/console doctrine:database:create