skip to Main Content

I’m trying to user docker-compose for mysql and phpmyadmin, but I’m getting an authentication error when trying to log in to phpmyadmin.

I’ve tried several configurations on the yaml file, but without any success.

version: '3'

services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_DATABASE: mydb
      MYSQL_USER: root
      MYSQL_PASSWORD: admin
      MYSQL_ROOT_PASSWORD: admin
    volumes:
      - my-db:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    links:
      - db
    ports:
      - 8080:80
    restart: always
    environment:
      PMA_USER: root
      PMA_PASSWORD: admin

    volumes:
      my-db: {}

When I try logging in to phpmyadmin i get the following errors:

mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password] mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client

I tried to change the yml to:

version: '3'

  services:

    db:
      image: mysql:57
      restart: always
      environment:

After this, the container no longer starts, and it gives the following message:

docker_db_1 exited with code 1

2

Answers


  1. This works fine:

    version: '3'
    
    services:
    
      db:
        image: mysql:5.7
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
          MYSQL_DATABASE: mydb
          MYSQL_USER: root
          MYSQL_PASSWORD: admin
          MYSQL_ROOT_PASSWORD: admin
        volumes:
          - my-db:/var/lib/mysql
    
      phpmyadmin:
              image: phpmyadmin/phpmyadmin:latest
              links:
                - db
              ports:
                - 8080:80
              restart: always
              environment:
                  PMA_USER: root
                  PMA_PASSWORD: admin
    
    volumes:
      my-db: {}
    

    Remember to delete the volume before running (in case you run into issues).

    Login or Signup to reply.
  2. I just copied this code in docker-compose.yml

    version: '3'
    
    services:
    
      db:
        image: mysql
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
          MYSQL_DATABASE: mydb
          MYSQL_USER: root
          MYSQL_PASSWORD: admin
          MYSQL_ROOT_PASSWORD: admin
        volumes:
          - my-db:/var/lib/mysql
    
      phpmyadmin:
              image: phpmyadmin/phpmyadmin:latest
              links:
                - db
              ports:
                - 8080:80
              restart: always
              environment:
                  PMA_USER: root
                  PMA_PASSWORD: admin
    
    volumes:
      my-db: {}
    

    and ran the command docker stack deploy -c docker-compose.yml mysqllab

    This is the result

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search