I illustrate my question with the help of docker containers but this example is orthogonal to the rest of the problem. In fact any program that allows the use of bridge interfaces and ssh would do.
I use a Docker container which runs a sshd
daemon in the background which is spawned by supervisord
which runs in the foreground. I mainly use ssh to have a secure way of X11-forwarding without having to bind mount /tmp/.X11-unix
into may container and totally exposing the socket to the container. If I use docker top containername
right after I started the container I get the following output:
UID PID PPID C STIME TTY TIME CMD
root 4732 535 1 19:56 ? 00:00:00 /usr/bin/python /usr/bin/supervisord
root 4745 4732 0 19:56 ? 00:00:00 /usr/sbin/sshd
which is as expected. Now, I exposed port 22 on the container to port 5000 on the host. Hence, I can login into my container using ssh -X username@localhost -p 5000
. I know how ssh works when client and host are different computers and on different networks but I have some questions when client and host are one the same computer (in my case client is my normal machine and host is the container on my normal machine). I know that docker sets up a bridge between the physical network device on my normal machine and the virtual network device on my machine.
But how exactly do my normal machine and the container communicate with each other? Do they use the IP addresses assigned to them by the bridge device and communicate via those?
How are the ports involved in this process do they remove the need to use IP addresses?
Is there a most efficient/recommended way of using ssh when client and host are on the same machine and configured in the way I just outlined.
Extensive internet search did not reveal sufficient answers. That being said I, of course, would not assert that such a site does not exist!
How do docker containers on the same host communicate?
be a more accurate title for this question?ssh
doesn't care what happens at the lower layer. I don't think there exist anyssh
-specific answer.