Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a docker container have its own TCP/IP stack?

I'm trying to understand what's happening under the hood to a network packet coming from the wire connected to the host machine and directed to an application inside a Docker container.

If it were a classic VM, I know that a packet arriving on the host would be transmitted by the hypervisor (say VMware, VBox etc.) to the virtual NIC of the VM and from there through the TCP/IP stack of the guest OS, finally reaching the application.

In the case of Docker, I know that a packet coming on the host machine is forwarded from the network interface of the host to the docker0 bridge, that is connected to a veth pair ending on the virtual interface eth0 inside the container. But after that? Since all Docker containers use the host kernel, is it correct to presume that the packet is processed by the TCP/IP stack of the host kernel? If so, how?

I would really like to read a detailed explanation (or if you know a resource feel free to link it) about what's really happening under the hood. I already carefully read this page, but it doesn't say everything.

Thanks in advance for your reply.

like image 958
Manuel Durando Avatar asked Jul 07 '14 12:07

Manuel Durando


People also ask

Do Docker containers have their own IPS?

By default, the container is assigned an IP address for every Docker network it connects to. The IP address is assigned from the pool assigned to the network, so the Docker daemon effectively acts as a DHCP server for each container. Each network also has a default subnet mask and gateway.

Does Docker use TCP?

The Docker daemon can listen for Docker Engine API requests via three different types of Socket: unix , tcp , and fd .

Does Docker container have same IP as host?

On Docker for Linux, the IP address of the gateway between the Docker host and the bridge network is 172.17. 0.1 if you are using default networking. Do you see the problem already? They are different, so you cannot simply run docker-compose up -d and all operating systems behave the same.

What is the IP of Docker container?

The default subnet for a docker network is 172.17. 0.0/16. Knowing these, we will now see the different methods that can be used to find out the IP address of a docker container in a network.


1 Answers

The network stack, as in "the code", is definitely not in the container, it's in the kernel of which there's only one shared by the host and all containers (you already knew this). What each container has is its own separate network namespace, which means it has its own network interfaces and routing tables.

Here's a brief article introducing the notion with some examples: http://blog.scottlowe.org/2013/09/04/introducing-linux-network-namespaces/ and I found this article helpful too: http://containerops.org/2013/11/19/lxc-networking/

I hope this gives you enough pointers to dig deeper.

like image 137
TvE Avatar answered Sep 22 '22 19:09

TvE