skip to Main Content

When I start MySQL :

docker run --rm -d -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v /Docker/data/matos/mysql:/var/lib/mysql mysql:5.7

And start PHPMyAdmin :

docker run --rm -d -e PMA_HOST=172.17.0.1 phpmyadmin/phpmyadmin:latest

PMA cannot connect to the DB server.
When I try with PMA_HOST=172.17.0.2 (which is the address assigned to the MySQL container), it works.
But :

  • as MySQL container publishes its 3306 port, I think it should be reachable on 172.17.0.1:3306.
  • I don’t want to use the 172.17.0.2 address because the MySQL container can be assigned another address whenever it restarts

Am I wrong ?

(I know I can handle this with docker-compose, but prefer managing my containers one by one).

(My MySQL container is successfully telnetable from my laptop with telnet 172.17.0.1 3306).

(My docker version : Docker version 20.10.3, build 48d30b5).

Thanks for your help.

3

Answers


  1. Chosen as BEST ANSWER

    Just found out the problem.

    My ufw was active on my laptop, and did not allow explicitly port 3306.

    I managed to communicate between PMA container and MySQL, using 172.17.0.1, either by disabling ufw or adding a rule to explicitly accept port 3306.

    Thanks @kidustiliksew for your quick reply, and the opportunity you gave me to test user-defined networks.


  2. maybe it’s a good idea to use docker-compose.
    Create a docker-compose.yml file and inside declare two services, one web and the other db, then you can reference them through their service names (web, db)

    ex: PMA_HOST=db
    
    Login or Signup to reply.
  3. Create a new docker network and start both containers with the network

    docker network create my-network
    
    docker run --rm -d --network my-network -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -v /Docker/data/matos/mysql:/var/lib/mysql --name mysql mysql:5.7
    
    docker run --rm -d --network my-network -e PMA_HOST=mysql phpmyadmin/phpmyadmin:latest
    

    Notice in the command that I’ve given the mysql container a name ‘mysql’ and used it as the address for phpmyadmin

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