0
I have two Docker-Compose.yml
in the first is defined my database:
# Docker-compose com banco mysql e postgress junto com phpmyadmin e PGADMIN
version: '3'
services:
# MYSQL
db:
image: mysql
container_name: db_mysql
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: "admin"
ports:
- 3306:3306
networks:
- mysql_net
adminer:
image: adminer
restart: always
ports:
- 8081:8080
networks:
- mysql_net
# POSTGRES
postgres:
image: postgres
container_name: postgres
environment:
POSTGRES_PASSWORD: admin
ports:
- "5432:5432"
pgadmin4:
image: dpage/pgadmin4
container_name: pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- "15432:80"
networks:
mysql_net:
driver: bridge
In my second Docker-Compose is set a small application in PHP.
version: '3'
services:
nginx:
image: richarvey/nginx-php-fpm
ports:
- "8080:80"
container_name: nginx
volumes:
- ./code:/var/www/html
networks:
- mysql_net
networks:
mysql_net:
external: true
The problem is that my PHP application is not able to see the mysql database, always returns the error
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve in /var/www/html/cap1/mysql_lista.php on line 4
My connection string looks like this: $conn = mysqli_connect("db_mysql", 'root', 'admin', 'livros');
If I create the mysql container inside the Docker-Compose that my PHP is running it works, but if I try to separate it already from the error.
I also tried to connect using the mysql Docker IP and also did not roll.
I’m not a deep connoisseur of Docker and it’s taking my sleep away.
I’d appreciate it if someone could help.
in the application’s Docker-Compose tries to define network as instead of
mysql_net
fordb_mysql_net
– Skywalker
ERROR: Network db_mysql_net declared as External, but could not be found. Please create the network Manually using
docker network create db_mysql_net
and Try Again.– Cesar Vinicius