Docker: how to open ports to the host machine?
<p>What could be the reason for Docker containers not being able to connect via ports to the host system?</p>

<p>Specifically, I'm trying to connect to a MySQL server that is running on the Docker host machine (<code>172.17.0.1</code> on the Docker bridge). However, for some reason port <code>3306</code> is always closed.</p>

<p>The steps to reproduce are pretty simple:</p>

<ol>
<li>Configure MySQL (or any service) to listen on <code>0.0.0.0</code> (<code>bind-address=0.0.0.0</code> in <code>~/.my.cnf</code>)</li>
<li><p>run</p>

<pre><code>$ docker run -it alpine sh
# apk add --update nmap
# nmap -p 3306 172.17.0.1
</code></pre></li>
</ol>

<p>That's it. No matter what I do it will always show </p>

<pre><code>PORT     STATE  SERVICE
3306/tcp closed mysql
</code></pre>

<p>I've tried the same with an ubuntu image, a Windows host machine, and other ports as well.</p>

<p>I'd like to avoid <code>--net=host</code> if possible, simply to make proper use of containerization.</p>