<p>I am using kubernetes (by windows 10 - docker desktop).</p>
<p>I am using mysql, that is running by helm 3 (loaded from bitnami repository).</p>
<p>I am creating another application.
For now, I am testing on docker (not in kubernetes yet).</p>
<p>Everything is fine, but when trying to connect the database from my project
(BTW - Project works fine, but not when running on docker).</p>
<p>Something like:</p>
<pre><code>docker run --name test-docker --rm my-image:tag --db &quot;root:12345@tcp(127.0.0.1:3306)/test&quot; 
</code></pre>
<p>(db is a parameter to to connect to db).</p>
<p>I get the message:</p>
<pre><code>2022-02-21T12:18:17.205Z        FATAL   failed to open db: could not setup schema: cannot create jobs table: dial tcp 127.0.0.1:3306: connect: connection refused
</code></pre>
<p>I have investigate a little, and find that the problem may be because the dockers running need to run on the same network.
(Nonetheless, they are actually dockers, when one is running by helm tool for K8S).</p>
<p>this is on:
<a href="https://www.digitalocean.com/community/tutorials/how-to-inspect-kubernetes-networking" rel="nofollow noreferrer">kubernetes networking</a></p>
<p>When I run:</p>
<pre><code>nsenter -t your-container-pid -n ip addr
</code></pre>
<p>the pid is not directory, so I get the message:</p>
<pre><code>/proc/&lt;pid&gt;/ns/net - No such file or directory
</code></pre>
<p>How can I eventually run my project that can use the mysql (running in dockers on K8S)?</p>
<p>Thanks.</p>

Eitan
<p>Docker containers are isolated from other containers and the external network by default. There are several options to establish connection between Docker containers:</p>
<ul>
<li><p>Docker sets up a default <code>bridge</code> network automatically, through which the communication is possible between containers and between containers and the host machine. Both your containers should be on the <code>bridge</code> network - for container with your project to connect to your DB container by referring to it's name. More details on this approach and how it can be set up is <a href="https://docs.docker.com/network/network-tutorial-standalone/#use-the-default-bridge-network" rel="nofollow noreferrer">here</a>.</p>
</li>
<li><p>You can also create user-defined bridge network - basically, your own custom bridge network - and attach your Docker containers to it. In this way, both containers won't be connected to the default  <code>bridge</code>  network at all. Example of this approach is described in details <a href="https://docs.docker.com/network/network-tutorial-standalone/#use-user-defined-bridge-networks" rel="nofollow noreferrer">here</a>.</p>
<ol>
<li>First, user-defined network should be created:</li>
</ol>
<pre><code>docker network create &lt;network-name&gt;
</code></pre>
<ol start="2">
<li>List your newly created network and check with <code>inspect</code> command its IP address and that no containers are connected to it:</li>
</ol>
<pre><code>docker network ls
docker network inspect &lt;network-name&gt;
</code></pre>
<ol start="3">
<li>You can either connect  your containers on their start with  <code>--network</code>  flag:</li>
</ol>
<pre><code>docker run -dit --name &lt;container-name1&gt; --network &lt;network-name&gt; 
docker run -dit --name &lt;container-name2&gt; --network &lt;network-name&gt; 
</code></pre>
<p>Or attach running containers by their name or by their ID to your newly created network by <code>docker network connect</code> - more options are listed <a href="https://docs.docker.com/engine/reference/commandline/network_connect/" rel="nofollow noreferrer">here</a>:</p>
<pre><code>docker network connect &lt;network-name&gt; &lt;container-name1&gt;
docker network connect &lt;network-name&gt; &lt;container-name2&gt;
</code></pre>
<ol start="4">
<li>To verify that your containers are connected to the network, check again the  <code>docker network inspect</code>  command.</li>
</ol>
</li>
</ul>
<p>Once connected in network, containers can communicate with each other, and you can connect to them using another container’s IP address or name.</p>
<p><strong><strong>EDIT</strong>:</strong> As suggested by @Eitan, when referring to the network instead of a changing IP address  in <code>root:12345@tcp(127.0.0.1:3306)/test</code>, special DNS name <code>host.docker.internal</code> can be used - it resolves to the internal IP address used by the host.</p>
