<p>In a Kubernetes pod, I have:</p>

<ul>
<li><code>busybox</code> container running in a <code>dind</code> container</li>
<li><code>fluentd</code> container</li>
</ul>

<p>I understand if <code>dind</code> wants to access <code>fluentd</code>, it needs to simply connect to localhost:9880. But what if <code>busybox</code> wants to access <code>fluentd</code> as the depicted diagram below. Which address should I use?</p>

<p><a href="https://i.stack.imgur.com/T85n2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T85n2.png" alt="dind access to another container"></a></p>

aldred
<p>These tips may help you:</p>

<p><strong>1. First approach</strong></p>

<p>From inside the docker:latest container, where you were trying to access it originally, it will be available on whatever hostname is set for the docker:dind container. In this case, you used --name dind, therefore curl dind:busybox_port would give you the standard.</p>

<p>And then you could from inside the docker:dind container (busybox) connect to fluentd, it will be available on localhost:9880.</p>

<p><strong>2. Second approach</strong></p>

<p>Another approach is to  <strong>EXPOSE  [/&lt;protocol>...]</strong> and in this case we assume that busyboox and fluentd are in different networks
You can also specify this within a docker run command, such as:</p>

<pre><code>$ docker run --expose=1234 busybox
</code></pre>

<p>But <strong>EXPOSE</strong> will not allow communication via the defined ports to containers outside of the same network or to the host machine. To allow this to happen you need to publish the ports.</p>

<p><strong>Publish</strong> ports and map them to the host</p>

<p>To publish the port when running the container, use the <strong>-p</strong> flag on docker run to publish and map one or more ports, or the <strong>-P</strong> flag to publish all exposed ports and map them to high-order ports.</p>

<pre><code>$ docker run -p 80:80/tcp -p 80:80/udp busybox
</code></pre>

<p>And then connect from busybox to fluentd using <strong>localhost:9880</strong></p>

<p>You can find more information here: <a href="https://applatix.com/case-docker-docker-kubernetes-part-2/" rel="nofollow noreferrer"><code>docker-in-docker</code></a>.</p>

<p>I hope it helps.</p>
