Oi !
Estou criando meu ambiente de desenvolvimento em docker. Mas estou com alguns problemas:
Eu consigo me conectar no container mysql por um SGBD, porém eu não consigo me conectar através do php-fpm, gera um erro :
SQLSTATE[HY000] [2002] Connection refused.
Segue minha configuração:
docker-compose.yml
version: "3"
services:
nginx:
image: "nginx:1.17.2"
container_name: "nginx-php-general"
volumes:
- "./nginx/www:/usr/share/nginx/html/"
- "./nginx/config/1-web.conf:/etc/nginx/conf.d/1-web.conf"
- "./nginx/logs/web.access.log:/var/log/nginx/web.access.log"
- "./nginx/logs/web.error.log:/var/log/nginx/web.error.log"
ports:
- "80:80"
networks:
- "networks-php-general"
depends_on:
- "php-fpm"
php-fpm:
build:
"./php"
container_name: "php-fpm-php-general"
# Since PHP is running in its own environment (container) it doesn't have access to the code.
# In order to fix this, we need to mount the code folder in the PHP container too.
# This way Nginx will be able to serve any static files, and PHP will be able to find the files
# it has to interpret. One final change to the docker-compose.yml
volumes:
- "./nginx/www:/usr/share/nginx/html/"
networks:
- "networks-php-general"
mysql:
image: "mysql:8.0.17"
container_name: "mysql-php-general"
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "default-base"
MYSQL_USER: "guest"
MYSQL_PASSWORD: ""
ports:
- "3306:3306"
networks:
- "networks-php-general"
networks:
networks-php-general:
driver: "bridge"
conexao.php
<?php
try {
$dbh = new PDO('mysql:host=mysql-php-general;port=3306;dbname=default-base', 'guest', '');
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Fora a conexão entre container mysql e php-fpm as demais partes estão funcionando certinho.
Quem puder me ajudar ficar muito grato, estou quebrando a cabeça para saber o que está acontecendo.
Vlw!