Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

username1's avatar

PDOException (2002) HELP SQLSTATE[HY000] [2002] Connection refused

good day Im running mysql in docker, but something went wrong, I don't know the main reason, I did search already but didn't find the answer yet. pls help me I'm new in docker thank you.

the error message,,

 public function createConnection($dsn, array $config, array $options)
{
    $username = Arr::get($config, 'username');

    $password = Arr::get($config, 'password');

    try {
        $pdo = new PDO($dsn, $username, $password, $options);
    } catch (Exception $e) {
        $pdo = $this->tryAgainIfCausedByLostConnection(

my .env file,,

DB_CONNECTION=mysql
DB_HOST=0.0.0.0
DB_PORT=3306
DB_DATABASE=eca01
DB_USERNAME=root
DB_PASSWORD=admin123
DB_PREFIX=tb_
0 likes
14 replies
username1's avatar

@Sinnbeck i tried it and this is the error, PDOException (2002) HELP SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

username1's avatar

version: '3.8'

networks: # Docker Network laraveldockerize:

services:

# Webserver Services
webserver:
    image: httpd:latest
    container_name: eca_apache
    restart: unless-stopped
    ports:
        - "8080:80"
    volumes:
        - .:/var/www/html
    depends_on:
        - php
        # - mysql
    networks:
        - laraveldockerize

# MySQL Services
# mysql:
#     image: mysql:5.7
#     container_name: eca_mysql
#     restart: always
#     # tty: true
#     ports:
#         - "33061:3306"
#     environment:
#         MYSQL_DATABASE: ${DB_DATABASE}
#         # MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
#         # MYSQL_PASSWORD: ${DB_PASSWORD}
#         # MYSQL_USER: ${DB_USERNAME}
#         # SERVICE_TAGS: dev
#         # SERVICE_NAME: mysql
#         # MYSQL_DATABASE: 'eca-server02'
#         MYSQL_ALLOW_EMPTY_PASSWORD: 1
#         MYSQL_PASSWORD: ""
#     # volumes:
#     #     - ./dockerize/mysql/data:/var/lib/mysql
#     networks:
#         - laraveldockerize
# PHP Services
php:
    build:
        context: .
        dockerfile: ./.docker/Dockerfile
    container_name: eca_php
    volumes:
        - .:/var/www/html
    ports:
        - 9000:80
    networks:
        - laraveldockerize

# Composer Services
composer:
    image: composer:latest
    container_name: eca_composer
    volumes:
        - .:/var/www/html
    working_dir: /var/www/html
    depends_on:
        - php
    networks:
        - laraveldockerize

# NPM Services
npm:
    image: node:14.9
    container_name: eca_npm
    volumes:
        - .:/var/www/html
    working_dir: /var/www/html
    entrypoint: ['npm']

# Artisan Services
artisan:
    build:
        context: .
        dockerfile: ./.docker/Dockerfile
    container_name: eca_artisan
    volumes:
        - .:/var/www/html
    # depends_on:
    #     - mysql
    working_dir: /var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
    networks:
        - laraveldockerize
username1's avatar

I commented mysql services, since pulled a new one from docker hub. and its container name is ecs-mysql

Sinnbeck's avatar

@username1 You still need it to be in your docker-compose.yml to be able to use it in that project. You can point the image: to it

image: ecs-mysql

Add it back in and rebuild

username1's avatar

@Sinnbeck do i need to compose a new one? since i commented it. and that mysql that i commented still in my docker container but I'm not running it. only the mysql that i pulled in dockerhub.

Sinnbeck's avatar

@username1 Stop the one you pulled in. Add it to that docker-compose.yml and rebuild. You might need to remove the old container if the data isnt compatible.

username1's avatar

i did what you told, but the error still the same.

Please or to participate in this conversation.