skip to Main Content

I am trying to run java web app. Thus, I must setup MySQL, phpmyadmin and Apache Tomcat for accessing website. I want to use the docker and its docker-compose application to make installation easier (If I may learn).

I could not set mysql and phpmyadmin applications to work together. If I can get past this first step, I will try to install tomcat.

This is my codes which is used(docker-compose.yml)

version: '2'
services:
    db:
        image: mysql
        restart: always
        ports:
            - "3306:3306"
        environment:
            MYSQL_DATABASE: myDb
            MYSQL_USER: admin
            MYSQL_PASSWORD: 12345
            MYSQL_ROOT_PASSWORD: root
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
        - "8080:80"
        environment:
            MYSQL_USER: admin
            MYSQL_PASSWORD: 12345
            MYSQL_ROOT_PASSWORD: root
        depends_on: 
            - db
        links:
            - db

I open the above codes with docker-compose up in the command line application.

I’m going to http://localhost:8080/ page, I’m typing admin for Username, 12345 for password.

The errors I get are:

Cannot log in to MySQL server
mysqli_real_connect (): The server requested authentication method
mysqli_real_connect (): (HY000 / 2054): The server requested authentication method

How can I install the applications (mysql, phpmyadmin, tomcat) with docker-compose?

2

Answers


  1. Chosen as BEST ANSWER

    Currently phpmyadmin and MySQL can work together. It is solved.

    PLAN A: This is my docker-compose.yml file:

    version: '2'
    services:
        db:
            container_name: db
            image: mysql
            restart: always
            ports:
                - "3306:3306"
            environment:
                MYSQL_DATABASE: myDb
                MYSQL_USER: admin
                MYSQL_PASSWORD: 12345
                MYSQL_ROOT_PASSWORD: root
            command: --default-authentication-plugin=mysql_native_password
        phpmyadmin:
            depends_on: 
                - db
            container_name: phpmyadmin
            image: phpmyadmin/phpmyadmin
            restart: always
            ports:
                - "8080:80"
            environment:
                MYSQL_USER: admin
                MYSQL_PASSWORD: 12345
                MYSQL_ROOT_PASSWORD: root
                PMA_HOST: db
    

    Now, you can go into MySQL via phpmyadmin at http://localhost:8080

    It can also be solved by this method.

    PLAN B: This is my docker-compose.yml file:

    version: '2'
    services:
        db:
            container_name: db
            image: mysql
            restart: always
            ports:
                - "3306:3306"
            environment:
                MYSQL_DATABASE: myDb
                MYSQL_USER: admin
                MYSQL_PASSWORD: 12345
                MYSQL_ROOT_PASSWORD: root
        phpmyadmin:
            depends_on: 
                - db
            container_name: phpmyadmin
            image: phpmyadmin/phpmyadmin
            restart: always
            ports:
                - "8080:80"
            environment:
                MYSQL_USER: admin
                MYSQL_PASSWORD: 12345
                MYSQL_ROOT_PASSWORD: root
                PMA_HOST: db
    

    Command line's commands:

    $ docker stop phpmyadmin
    $ docker exec -it db bash
    $ mysql -u root -proot
    $ ALTER USER root IDENTIFIED WITH mysql_native_password BY 'root';
    $ exit
    $ exit
    $ docker start phpmyadmin
    

    Now, you can go into MySQL via phpmyadmin at http://localhost:8080

    Reference: phpMyAdmin on MySQL 8.0


  2. version: '3.1'
        services:
          db:
            image: mysql
            command: --default-authentication-plugin=mysql_native_password
            restart: always
            ports:
              - 3307:3306
            environment:
              MYSQL_ROOT_PASSWORD: 1234
          phpmyadmin:
            image: phpmyadmin/phpmyadmin
            restart: always
            ports:
              - 8080:80
            environment:
              MYSQL_ROOT_PASSWORD: 1234
            links:
              - db
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search