phpmyadmin / docker

Docker container for phpMyAdmin
https://hub.docker.com/_/phpmyadmin
GNU General Public License v3.0
665 stars 456 forks source link

All fine with the first connection, then error all the time: Connection refused #387

Closed Zeppgoespro closed 1 year ago

Zeppgoespro commented 1 year ago

Hello! I've got a problem.

I made Dockerfile and docker-compose.yml with this code:

Dockerfile:

FROM php:8.1-fpm

RUN apt-get update && apt-get install -y \
        curl \
        wget \
        git \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
        libzip-dev \
    && docker-php-ext-install -j$(nproc) iconv mysqli pdo_mysql zip \
    && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

USER www-data:www-data

WORKDIR /var/www

CMD ["php-fpm"]

docker-compose:

version: '3'

networks:
  internal:

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - '8080:80'
    volumes:
      - ./sites:/var/www
      - ./config/nginx:/etc/nginx/conf.d
      - ./data/logs:/var/log/nginx/
    depends_on:
      - php
      - mysql
    networks:
      - internal

  php:
    build:
      context: ./config/php
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./sites:/var/www
      - ./config/php/php.ini:/usr/local/etc/php/php.ini
    ports:
      - '9000:9000'
    networks:
      - internal

  mysql:
    image: mysql:latest
    container_name: mysql
    restart: unless-stopped
    command:
      - --default-authentication-plugin=mysql_native_password
      - --innodb_use_native_aio=0
    ports:
      - '3306:3306'
    volumes:
      - ./data/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: bobafett
    networks:
      - internal

  phpmyadmin:
    image: phpmyadmin:5.1.3
    container_name: phpmyadmin
    environment:
      - PMA_ARBITRARY=1
      - PMA_HOST=mysql
    restart: always
    ports:
      - '8081:80'
    networks:
      - internal

Running >docker-compose up -d --build.

It works fine for the first time. I came in to the phpmyadmin (localhost:8081), entered server/user/password, all fine. Inside i done nothing, closed tab. Then i run >docker-compose down. After new >docker-compose up -d --build i can't get into. Mean i enter server/user/password and get:

Cannot log in to the MySQL server

And

mysqli::real_connect(): (HY000/2002): Connection refused

I get it all the time. My first ytb tutorial about docker + phpmyadmin + mysql ended like this too. It worked for the first connection, after >docker-compose down >docker-compose up this happens.

All containers are 'green' and working.

img

williamdes commented 1 year ago

Hi! First I think we can say for sure this is not a phpMyAdmin issue. Then I would say you should try to login in the MySQL container to figure out what is wrong

docker exec -it mysql bash
mysql -u root - p

If you can login then we can maybe try to find what is wrong between the containers. If not this is all up to the MySQL container.

Here is my local dev config: https://github.com/wdesportes/phpmyadmin-local-setup/blob/main/docker-compose.yml

Zeppgoespro commented 1 year ago

Hi! First I think we can say for sure this is not a phpMyAdmin issue. Then I would say you should try to login in the MySQL container to figure out what is wrong

docker exec -it mysql bash
mysql -u root - p

If you can login then we can maybe try to find what is wrong between the containers. If not this is all up to the MySQL container.

Here is my local dev config: https://github.com/wdesportes/phpmyadmin-local-setup/blob/main/docker-compose.yml

Thx for reply! Actually i fixed the problem, don't know how for sure though. I am just a beginner. So i made this and that and more, now all fine 😂 And thx for repo, looks like i may learn much from that.