-1
Hi !
I’m creating my Docker development environment. But I’m having some problems:
I can connect to the mysql container by an SGBD, but I can’t connect through php-fpm, it generates an error :
SQLSTATE[HY000] [2002] Connection refused. 
Follow my setup:
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"
    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"
php connection.
<?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();
}
Apart from the connection between mysql container and php-fpm the other parts are working right.
Who can help me be very grateful, I’m cracking my head to know what’s going on.
Vlw!
It was a great observation friend I made the appropriate changes, thank you. However it is still generating the error.
– JhAndrade