Next I curl to the same loopback but on port 8080 and I get a response from the container running Apache on port 8080. As you can see, I get a return from the container running Apache on port 80. So first we curl to the loopback which will by default use port 80. Let’s run some curl commands on the container web1 to see if we can access services on web2…
![how to listen to docker network mode host how to listen to docker network mode host](https://www.techwhoop.com/wp-content/uploads/2017/09/Pickaface.jpg)
Take for instance the host loopback address of 127.0.0.1. So since we share network interfaces it should make sense that we can communicate across them. This should remind you of the host mode demo we did where a container saw the exact network interfaces of the host. So as you can see, the network config on both containers looks identical. Pretty easy right? So let’s hop into web1 and web2 containers with docker exec and see what we have… So we run our second container but we specify that it’s network mode should be set to ‘container’ and then specify the container we want to map the new container (web2) into. We’ll do that with this command… docker run -d -name web2 -net=container:web1 jonlangemak/docker:web_container_8080 Now, let’s run a second container in mapped container mode. Nothing new here, we just mapped a port into a container that’s running in the default bridge mode. So let’s try browsing to our host docker1 (10.20.30.100)… Here we can see that it’s running and that port 80 on the host has been mapped to port 80 on the container. Once it’s downloaded let’s take a look and make sure its running…
How to listen to docker network mode host download#
So let’s download web_container_80 and run it with port 80 on the docker host mapped to port 80 on the container… docker run -d -name web1 -p 80:80 jonlangemak/docker:web_container_80 These containers aren’t much different from what we had before, save the fact that I made the index pages a little more noticeable. Web_container_8080 – Runs CentOS image with Apache configured to listen on port 8080 Web_container_80 – Runs CentOS image with Apache configured to listen on port 80
![how to listen to docker network mode host how to listen to docker network mode host](https://i.ytimg.com/vi/PzpUvfRXaYw/maxresdefault.jpg)
In this blog I’ll be using two docker images… This leads to some interesting options in regards to how containers can consume network services. Essentially, all you’re doing is placing a new containers network interface inside an existing containers network stack. Mapped container network mode is also referred to as ‘container in container’ mode. That being said, let’s get right into it. We haven’t covered the ‘none’ option but that will come up in future posts when we discuss more advanced deployment options. In this post I want to cover what I’m considering the final docker provided network mode.