Why docker directly communicate with internet not thorough localhost - docker

i thought that docker will communicate with internet via localhost
so if i capture the packet,
docker_ip -> local_ip -> internet_ip
it would be like this.
but wireshark result was different
enter image description here
As you can see, docker only communicates with internet
and local only communicates with internet too.
how could it be?

Related

Why can my Docker app receive UDP data without publishing the port?

I'm learning Docker networking. I'm using Docker Desktop on Windows.
I'm trying to understand the following observations:
Short version in a picture:
Longer version:
First setup (data from container to host)
I have a simple app running in a container. It sends one UDP-datagram to a specific port on the host (using "host.docker.internal")
I have a corresponding app running on the host. It listens to the port and is supposed to receive the UDP-datagram.
That works without publishing any ports in docker (expected behavior!).
Second setup (data from host to container)
I have a simple app on the host. It sends one UDP-datagram to a specific port on the loopback network (using "localhost")
I have a corresponding app running in a container. It listens to the port and is supposed to receives the UDP-datagram.
That works only if the container is run with option -p port:port/udp (expected behavior!).
Third setup (combination of the other two)
I have an app "Requestor" running in a container. It sends a UDP request-message to a specific port on the host and then wants to receive a response-message.
I have a corresponding app "Responder" running on the host. It listens to the port and is supposed to receive the request-message. Then it sends a UDP response-message to the endpoint of the request-message.
This works as well, and - that's what I don't understand - without publishing the port for the response-message!
How does this work? I'm pretty sure there's some basic networking-knowledge that I simply don't have already to explain this. I would be pleased to learn some background on this.
Sidenote:
Since I can do curl www.google.com successfully from inside a container, I realize that a container definitely must not publish ports to receive any data. But there's TCP involved here to establish a connection. UDP on the other hand is "connectionless", so that can't be the (whole) explanation.
After further investigation, NAT seems to be the answer.
According to these explanations, a NAT is involved between the loopback interface and the docker0 bridge.
This is less recognizable with Docker Desktop for Windows because of the following (source):
Because of the way networking is implemented in Docker Desktop for Windows, you cannot see a docker0 interface on the host. This interface is actually within the virtual machine.

How do I choose which network interface to use from a Docker container?

I have 2 network interfaces on my Mac - en0 for regular Ethernet connection, en6 for a USB LTE modem, the latter has higher priority. I'm running a node.js app in a Docker container, when I make an outbound request from this container, I can see the IP of the modem. For some heavy requests I'd like to be able to use the regular Ethernet connection. Is this possible? Thanks

Can't connect to docker container running minecraft server online

So I've been trying to host my own Minecraft server for a while now and I hit a snag.
I have proxmox (192.168.2.100) running an ubuntnu server VM (192.168.2.101) which has a docker container running my Minecraft server. I can connect to the server locally just fine using the ubuntu's IP address and minecraft port, but when I try to port forward the server, I can't connect to it. I checked to see if my port was exposed or not and it is so I know it's not that.
This is the container that I'm using
Okay, so after a long time looking at configurations and some help from the proxmox forum, it turns out that my modem doesn't support NAT reflection which means that any attempts to access my server though my public IP on the same network wouldn't work at all. I used my phone's mobile network to test if I could access the server from outside my local network and it worked just fine!

How do I setup a docker container that I can connect to from any computer on my local network?

I'm trying to create a Docker container that I can connect to from any device on my local network. Specifically, this container: https://hub.docker.com/r/codercom/code-server. I've tried using Docker Desktop and Docker Toolbox but I've only been able to get it working on my host device. How do I configure my network or other settings to allow other devices on my local network to connect to the container?
I've tried following similar stackoverflow questions, docker forums, and youtube videos. I've tried setting of bridged network connections but nothing has worked for me.
These are some of the sites that I've been on and tried to replicate the solution to my similar problem.
https://forums.docker.com/t/bridge-with-docker-for-windows/30936
https://stackoverflow.com/questions/39111247/how-to-access-docker-container-from-another-machine-on-local-network
https://blog.oddbit.com/post/2014-08-11-four-ways-to-connect-a-docker/
Edit1: The command that I run is: docker run -it -p 127.0.0.3:8443:8443 -v "${PWD}:/home/coder/project" codercom/code-server --allow-http --no-auth This part works but when I try to access 127.0.0.3:8443 from a different computer on the same network it doesn't work. I've tried to solutions from the links that I posted above but I get the same result where the address that I put in fails to load.
What I want to do is host code-server from my desktop computer and allow for a device like a laptop to connect to the code-server. I'm currently on a windows 10 pro machine. Can anyone lead me into the right sort of direction?
Solution:
When I installed Docker for Windows, it creates a network called vEthernet (DockerNAT) (Usually with the IP 10.0.75.1)
My local machine had a network called local area connection with the IP 192.168.0.172(With this IP I was trying to access from other PCs).
So far, My local Machine had Two networks Connections so that I went to Control panel > NetWork and Sharing center > Change Adapter Settings I selected the two networks and I right-click selected Add to bridge. That creates a Third network called Ethernet.
At this point, I didn't know what was the Ip of Ethernet network, so I executed ipconfig command that shows me the IP 192.168.0.17(The settings of local area connection and vEthernet (DockerNAT) disappeared and the IP's 10.0.75.1 and 192.168.0.172 stop working).
With this new IP (192.168.0.17) I tried from another machine in the network and finally I could access to the container(192.168.0.17:9090).
Important if you have a firewall enabled then you need to execute the below script in PowerShell
if (!(Get-NetFirewallRule | where {$_.Name -eq “gitlab 9090”})) { New-NetFirewallRule -Name “gitlab 9090” -DisplayName “gitlab 9090” -Protocol tcp -LocalPort 9090 -Action Allow -Enabled True}
Replace the gitlab and port 9090 with your image name and port.

routing broadcast UDP in/out of Docker for Mac container

I want to run an application (the OLA server, olad) inside a container under Docker for Mac. (Version 18.06.1-ce-mac73 on Mojave, all up-to-date.) The particular OLA configuration I am using (for the Art-Net protocol) works by sending and receiving UDP broadcast data over port 6454 on a particular physical ethernet interface on the host, which is in turn connected to an external device under control. Normally, when starting the olad server, one specifies the interface or IP address on which it should send/receive the broadcast messages.
My struggle is getting the UDP messages to and from the interface from inside the container. I don't appear to have access to that physical interface or network inside the Docker for Mac container, even if I run with --network host. My understanding is that this is because of a quirk of the way Docker for Mac is implemented, with an extra VM between my container and the hardware. That VM sees the hardware, but I don't.
Simply running the docker instance with -p 6454:6454/udp doesn't work, either, maybe unsurprisingly. I could see where that might allow incoming traffic to the container to find its way to the server, but the server inside still can't find the outside network/device in the other direction. And I'm not sure how OSX would necessarily get that data from the interface to the docker bridge anyway.
How can I get direct, bidirectional access to that interface or network from inside the container? Or if I cannot, is there some kind of workaround, maybe via socat where I could tunnel that network in through a Unix socket that is shareable between host and container?

Resources