docker icon indicating copy to clipboard operation
docker copied to clipboard

phpMyAdmin can't connect to mysql - both on same network.

Open tcconway opened this issue 2 years ago • 4 comments

Somewhat new to Docker, so it might be a user error...

After having following several YT tutorials, I cannot get PHPMyAdmin to actually log in--I get the following errors:

  • mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
  • mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known

My setup is: Docker with the default Laravel setup. Both 'mysql' and 'phpmyadmin' are in the 'sail' network.

Here's my docker-compose.yml:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            retries: 3
            timeout: 5s
    phpmyadmin:
        depends_on:
            - mysql
        image: phpmyadmin
        environment:
            - PMA_HOST = mysql
            - PMA_PORT = 3306
        networks:
            - sail
        ports:
            - 8080:80
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sail-redis:/data'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "redis-cli", "ping"]
            retries: 3
            timeout: 5s
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
    sail-redis:
        driver: local

tcconway avatar May 01 '22 16:05 tcconway

Apparently setting - PMA_ARBITRARY=1 in the yml and then using 'mysql' during login works...

tcconway avatar May 01 '22 19:05 tcconway

Apparently setting - PMA_ARBITRARY=1 in the yml and then using 'mysql' during login works...

What about using

       environment:
            PMA_HOST: mysql
            PMA_PORT: 3306

it should work fine

williamdes avatar May 01 '22 19:05 williamdes

It's not working with PMA_HOST and PMA_PORT.

Having this...

        environment:
            - PMA_HOST = mysql
            - PMA_PORT = 3306

...doesn't work. I get the following errors when trying to log in: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known mysqli::real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known

When I use this...

        environment:
            - PMA_ARBITRARY=1

... I can type 'mysql' into the Server field and it allows me to log in.

Perhaps 'mysql' is not unique enough?

tcconway avatar May 01 '22 19:05 tcconway

Hi,

This is a bit strange, can you try the format I sent you to be sure this is not the cause of this issue ?

            PMA_HOST: mysql
            PMA_PORT: 3306

Perhaps 'mysql' is not unique enough?

It's just a name, phpMyAdmin will not complain about it ;)

williamdes avatar Aug 09 '22 23:08 williamdes

hey, same problems here, same network, and two syntax try

gabrielmustiere avatar Dec 02 '22 15:12 gabrielmustiere

hey, same problems here, same network, and two syntax try

What is your docker compose file?

williamdes avatar Dec 03 '22 08:12 williamdes

i have found the solution, juste remove PMA_PORT: 3306, only the host is enough

gabrielmustiere avatar Dec 03 '22 12:12 gabrielmustiere

The workaround for me was to use the local address of the docker host 10.10.10.x. Using the hostname would fail... I'll have to work out why the host couldn't resolve.

jaggersystems avatar Sep 25 '23 22:09 jaggersystems

I'll have to work out why the host couldn't resolve.

What is the host ?

Is it external on the computer name ?

williamdes avatar Sep 26 '23 11:09 williamdes

I'll have to work out why the host couldn't resolve.

What is the host ?

Is it external on the computer name ?

Local. I have the db and docker/phpmyadmin running on the same host.

jaggersystems avatar Sep 26 '23 11:09 jaggersystems