0

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.

2

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

this is the suggested way by doc, deprecated --link flag might work as well. docker run -d --name phpmyadmin --link my_mysql_container:db -p 8080:80 phpmyadmin
1

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.