Docker container hangs internet connection

Here is the interesting situation:

My host machine is Ubuntu. VirtualBox is installed.

In VirtualBox I have a Debian machine.

In the Debian machine I run the container:

docker run --name my-cge-container --volume="${HOME}":/home/sharedhome/ -it kambi/castle-engine-cloud-builds-tools:cge-unstable bash

Everything is OK. There is Internet connection in the container.

After container runs for about 1 minute:

There is no Internet connection inside the container,

and no Internet in Debian machine, while there is Internet in Ubuntu host machine.

I stop container. Immediately there is Internet in Debian machine.

Start the container again. The situation repeats - no internet after 1 minutes and Internet is available after stopping container.

I repeated it several times/restarted Debian machine etc.

I installed docker tools via snap on the Debian machine. Maybe this is the problem while I am not sure. Maybe it’s something with Castle’s Dockerfile.

Well, I think the problem is because I installed docker tools from snap on Debian machine. I tried other containers:

docker run --name my-debian -it debian:bookworm-slim bas
docker run --name my-ubuntu -it ubuntu bash

The result is exactly the same. So it’s not related to CGE docker file.
While I also tried on Ubuntu host machine with normally installed docker tools - CGE container works fine.


My first guess would be to blame Virtual Box connection settings – maybe you have non-standard settings that somehow make the network drivers in the virtual machine “overloaded” after 1 minute? IOW, it would be independent from Docker at all. Searching the Internet I found a raport ,

Those VMs network adapters are NAT. Not sure why that fixes it, but it does.

In my Virtual Box usage, I see my network cards are indeed NAT.

As for Docker from snap – personally I’m always installing it using DEB packages, following Install Docker Engine on Ubuntu | Docker Docs . This approach has worked for me. So, as you say, maybe the problem is because of snap? Switching your installation to use DEB packages and testing should answer this.

My network adapter is NAT. I uninstalled docker engine (installed by snap), removed traces. Then installed docker from DEB packages. The issues remains. Then I found the topics networking - Docker container loses Internet access after setting Docker to use manually created bridge - Server Fault and VBox & Docker NAT/Bridge issues · Issue #4329 · moby/moby · GitHub

So the solution is to use (I verified it works with CGE container):

docker run --net=host

By default in docker bridge is used and the problem is with the bridge.

  • bridge The default network driver.
  • host Remove network isolation between the container and the Docker host.

So the problem was in fact related to aspects of running docker in VirtualBox machine.

1 Like