docker-compose:无法从我的LEMP堆栈访问phpMyAdmin

时间:2020-02-26 00:08:02

标签: php mysql docker phpmyadmin docker-compose

我刚刚使用docker和docker-compose创建了一个LEMP堆栈(Linux,Nginx,MariaDB,PHP-FPM)。 但是以某种方式,我无法通过phpMyAdmin访问我的数据库。

当我尝试访问phpMyAdmin Web服务器时,出现以下错误:

MySQL表示:文档

无法连接:设置无效。

数据包故障。预期收到0个1.数据包大小= 69

mysqli_real_connect():读取问候数据包时出错。 PID = 18

mysqli_real_connect():( HY000 / 2006):MySQL服务器已消失

phpMyAdmin尝试连接到MySQL服务器,服务器拒绝了该连接。您应该检查配置中的主机,用户名和密码,并确保它们与MySQL服务器管理员提供的信息相对应。

其余的工作正常。

这是我的docker-compose.yml文件:

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

这是我的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

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

使用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