# \[closed\] Docker container hangs internet connection

**URL:** <https://forum.castle-engine.io/t/closed-docker-container-hangs-internet-connection/1115>\
**Category:** Bugs\
**Created:** [March 15, 2024, 8:23am UTC](https://forum.castle-engine.io/t/closed-docker-container-hangs-internet-connection/1115 "2024-03-15T08:23:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rvasin](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/rvasin/32/56_2.png) [@rvasin](https://forum.castle-engine.io/u/rvasin)\
**Post date:** [March 15, 2024, 8:23am UTC](https://forum.castle-engine.io/t/closed-docker-container-hangs-internet-connection/1115/1 "2024-03-15T08:23:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rvasin](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/rvasin/32/56_2.png) [@rvasin](https://forum.castle-engine.io/u/rvasin)\
**Post date:** [March 15, 2024, 10:20am UTC](https://forum.castle-engine.io/t/closed-docker-container-hangs-internet-connection/1115/2 "2024-03-15T10:20:46Z")

</div>

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

```bash
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.

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [March 15, 2024, 11:08am UTC](https://forum.castle-engine.io/t/closed-docker-container-hangs-internet-connection/1115/3 "2024-03-15T11:08:04Z")

</div>

Hi,

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 [https://www.reddit.com/r/virtualbox/comments/sjzy14/vm\_loses\_network\_connection\_1\_minute\_after\_startup/](https://www.reddit.com/r/virtualbox/comments/sjzy14/vm_loses_network_connection_1_minute_after_startup/) ,

> 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](https://docs.docker.com/engine/install/ubuntu/) . 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.

---

<div class="post-metadata">

**Author:** ![rvasin](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/rvasin/32/56_2.png) [@rvasin](https://forum.castle-engine.io/u/rvasin)\
**Post date:** [March 15, 2024, 6:05pm UTC](https://forum.castle-engine.io/t/closed-docker-container-hangs-internet-connection/1115/4 "2024-03-15T18:05:39Z")

</div>

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](https://serverfault.com/questions/1111277/docker-container-loses-internet-access-after-setting-docker-to-use-manually-crea) and [VBox & Docker NAT/Bridge issues · Issue #4329 · moby/moby · GitHub](https://github.com/moby/moby/issues/4329)

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.

> **[Networking overview](https://docs.docker.com/network/)**
>
> Learn how networking works from the container's point of view

> - 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.
