1

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?

Shubham
  • 2,847
  • 4
  • 24
  • 37
Nickname
  • 49
  • 9
  • could you try login/access to `db` container from `php-admin` container with bash? – PPShein Jan 05 '19 at 16:04
  • I tried to some codes but I did not achieve. I think, my codes are wrong. Can you suggest a code? How can I do that? – Nickname Jan 05 '19 at 16:50
  • @PPShein I entered the bash screen from the docker using this code `docker exec -it desktop_db_1 /bin/bash` and I tried to connect inside with this code `mysql -uroot -proot` or `mysql -uadmin -p12345` and I accessed with successfully but I still can not access at `http://localhost:8080/` – Nickname Jan 05 '19 at 17:38

2 Answers2

1

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

Nickname
  • 49
  • 9
  • 1
    No tomcat in this question... but plan A and plan B are working both. very educational exercise for beginners docker. – MaxiReglisse Jun 18 '19 at 15:40
0
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
Aytac
  • 1
  • 1
    Welcome to SO. It would be nice if you could include a description on what you have changed, and how you think it answers the question. – Nappy Sep 02 '19 at 22:34