What could be the reason for Docker containers not being able to connect via ports to the host system?
Specifically, I'm trying to connect to a MySQL server that is running on the Docker host machine (172.17.0.1
on the Docker bridge). However, for some reason port 3306
is always closed.
The steps to reproduce are pretty simple:
- Configure MySQL (or any service) to listen on
0.0.0.0
(bind-address=0.0.0.0
in~/.my.cnf
) run
$ docker run -it alpine sh # apk add --update nmap # nmap -p 3306 172.17.0.1
That's it. No matter what I do it will always show
PORT STATE SERVICE
3306/tcp closed mysql
I've tried the same with an ubuntu image, a Windows host machine, and other ports as well.
I'd like to avoid --net=host
if possible, simply to make proper use of containerization.