Skip to content
Advertisement

docker-compose: cannot access to phpMyAdmin from my LEMP stack

I just created a LEMP stack (Linux, Nginx, MariaDB, PHP-FPM) with docker and docker-compose. But somehow, I cannot access to my database trough phpMyAdmin.

When I’m trying to reach the phpMyAdmin web-server, I got these errors:

MySQL said: Documentation

Cannot connect: invalid settings.

Packets out of order. Expected 0 received 1. Packet size=69

mysqli_real_connect(): Error while reading greeting packet. PID=18

mysqli_real_connect(): (HY000/2006): MySQL server has gone away

phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

The rest is working fine.

Here is my docker-compose.yml file:

version: "3.3"
services:

    nougat:  #Nginx Server
        image: tutum/nginx:latest
        ports:
            - "8080:80"
        links:
            - papaya  # PHP-FPM service
        volumes:
            - type: bind
              source: ./nginx
              target: /etc/nginx/sites-available

            - type: bind
              source: ./nginx
              target: /etc/nginx/sites-enabled

            - type: bind
              source: ./logs/nginx-error.log
              target: /var/log/nginx/error.log

            - type: bind
              source: ./logs/nginx-access.log
              target: /var/log/nginx/access.log

    papaya:  # PHP-FPM service
        build: .
        volumes:
            - type: bind
              source: ./public
              target: /usr/share/nginx/html

    mango:  # MariaDB database
        image: mariadb:10.5.1
        volumes:
            - type: bind
              source: ./mango_database
              target: /var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: admin

    pomegranate:  # phpMyAdmin web-service
        image: phpmyadmin/phpmyadmin:4.9.4
        restart: always
        links:
            - mango:mysql  # MySQL database
        ports:
            - "8081:80"
        environment:
            PMA_HOST: mysql
            PMA_USER: root
            PMA_PASSWORD: admin
            PMA_ARBITRARY: 1

And here is my Dockerfile:

FROM php:7.4.3-fpm

RUN docker-php-ext-install pdo pdo_mysql

RUN apt-get update -y && apt-get install -y libwebp-dev libjpeg62-turbo-dev libpng-dev libxpm-dev 
    libfreetype6-dev

RUN apt-get update && 
    apt-get install -y 
        zlib1g-dev 

RUN apt-get install -y libzip-dev

RUN docker-php-ext-install zip

RUN docker-php-ext-install gd

Thank you for your help in advance.

Advertisement

Answer

connect all your service together using networks

docker-compose.yml

version: "3.3"
services:

    nougat:  #Nginx Server
        image: tutum/nginx:latest
        ports:
            - "8080:80"
        networks:         # <-- Add this line
            - random_name # <-- Add this line
        # links:          # <-- Remove this
        #     - papaya    # <-- Remove this
        volumes:
            - type: bind
              source: ./nginx
              target: /etc/nginx/sites-available

            - type: bind
              source: ./nginx
              target: /etc/nginx/sites-enabled

            - type: bind
              source: ./logs/nginx-error.log
              target: /var/log/nginx/error.log

            - type: bind
              source: ./logs/nginx-access.log
              target: /var/log/nginx/access.log

    papaya:  # PHP-FPM service
        build: .
        networks:         # <-- Add this line
            - random_name # <-- Add this line
        volumes:
            - type: bind
              source: ./public
              target: /usr/share/nginx/html

    mango:  # MariaDB database
        image: mariadb:10.5.1
        networks:         # <-- Add this line
            - random_name # <-- Add this line
        volumes:
            - type: bind
              source: ./mango_database
              target: /var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: admin

    pomegranate:  # phpMyAdmin web-service
        image: phpmyadmin/phpmyadmin:4.9.4
        restart: always
        # links:            # <-- Remove this
        #     - mango:mysql # <-- Remove this
        ports:
            - "8081:80"
        networks:         # <-- Add this line
            - random_name # <-- Add this line
        environment:
            PMA_HOST: mysql
            PMA_USER: root
            PMA_PASSWORD: admin
            PMA_ARBITRARY: 1

networks:         # <-- Add this line
    random-name:  # <-- Add this line

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement