Container exits when given --net="host"

Hi everyone,
Whenever I add --net="host" to docker run command it fails with the following error:

Error response from daemon: ttrpc: closed: unknown

microservice-rust-mysql/docker-compose.yml at main · second-state/microservice-rust-mysql · GitHub is the docker-compose to reproduce

Additional discussion on discord: Discord

Please, share the output of

docker info

and

docker version

Searching for the error message there are many reports but so far I have seen only issues related to not officially supported host operating systems (Alpine, Gentoo) and the containerd version.

For example:

or

Full error log: satacker@pop-os:~/wasm_work/dapr-sdk-wasi/examples/docker_compose$ docker compos - Pastebin.com

Docker Info

Client:
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.15.1
    Path:     /usr/lib/docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.0.5
    Path:     /usr/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.17
    Path:     /usr/lib/docker/cli-plugins/docker-extension
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/lib/docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/lib/docker/cli-plugins/docker-scan

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 7
 Server Version: 22.06.0-beta.0-917-gf888bd4531.m
 Storage Driver: stargz
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.246GiB
 Name: docker-desktop
 ID: 46474eaa-3018-45b5-b5f4-b3daa5109431
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Docker Version:

Client: Docker Engine - Community
 Cloud integration: v1.0.29
 Version:           23.0.1
 API version:       1.42
 Go version:        go1.19.5
 Git commit:        a5ee5b1
 Built:             Thu Feb  9 19:47:01 2023
 OS/Arch:           linux/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.16.2 (95914)
 Engine:
  Version:          22.06.0-beta.0-917-gf888bd4531.m
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.18.4
  Git commit:       f888bd4531
  Built:            Wed Jan 18 09:47:42 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.14
  GitCommit:        9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

P.S. On the discord community of WasmEdge, one more member confirmed that only adding --net="host" to docker run or adding - network_mode: "host" to docker compose yaml causes this issue.
They also tried this code fix(shim): avoid stale state on empty hooks by 0xE282B0 · Pull Request #1 · 0xE282B0/runwasi · GitHub which worked for them.

Something is definitely wrong in your setup. Your client is for Docker 23.0.1 which could work, but it is recommended to use the same version as the version of your engine. You are using Docker Desktop and as far as I know, Docker Desktop does not support newer Docker Engine version than 20.10. Your engine however is 22.06.0 beta which was never released as stable version. After the beta, it was changed to 23.0.0-rc.

The version of your Desktop is 4.16.2 which is the same as the version of mine on my macOS, but one of the points of Docker Desktop is providing the same version on each platform inside a virtual machine.

How did you install Docker Desktop on Linux? Although I am not on my Linux now to check the versions but I doubt that Docker would release a stable Docker Desktop version on Linux like this.

How did you install Docker Desktop on Linux?

Used the given installation steps for docker desktop

I wanted to ask you to share the link, because I have seen people installing docker based on tutorials and not the documentation. And I also wanted to say that even if you followed the documentation you could do something differently, so it would help if you could share what you did. Then I realized that using wasm requires enabling beta features. Since your daemon is using stargz as storage driver which was added to the beta feature I enabled “Use containerd for pulling and storing images” feature and got the same versions. It looks like that feature was not updated with the stable Docker CE in the virtual machine.

Another important information is that you are using Docker Desktop. By the time of my previous comment switching between topics I forgot about the original question, but the fact is that using the host mode is rarely useful in Docker Desktop. You will never use the network of the actual host operating system, only the network of the virtual machine. I am not sure that was your intention.

Ohh, Install Docker Desktop on Debian | Docker Docs I am on popOs btw.

Another important information is that you are using Docker Desktop. By the time of my previous comment switching between topics I forgot about the original question, but the fact is that using the host mode is rarely useful in Docker Desktop. You will never use the network of the actual host operating system, only the network of the virtual machine. I am not sure that was your intention.

Okay, I had to use docker with containerd support because I am running it on wasi/wasm as a platform. And only docker desktop gave that option as far as I know.

That’s okay, but why do you need host network?

With my already-written code (without changing the URLs or passing another argument through the CLI), it sure is convenient to not compile based on the network setup by the docker. Is there a better way?

Convenient or not, you can’t always use already written code without modification if you want to use containers. In fact you often need to change the old ways. If you need wasm, I don’t know better way than Docker Desktop, although I am not using wasm. If you need Docker Desktop, you need to adapt. Without more information about your project, I don’t see how the host network would help. Using a reverse proxy is usually a better solution unless you want to configure the host network from a container.

What kind of URLs would you need to change?

Convenient or not, you can’t always use already written code without modification if you want to use containers. In fact you often need to change the old ways. If you need wasm, I don’t know better way than Docker Desktop, although I am not using wasm. If you need Docker Desktop, you need to adapt. Without more information about your project, I don’t see how the host network would help. Using a reverse proxy is usually a better solution unless you want to configure the host network from a container.

Okay, thanks for this. I’ll change stuff that I need to.

What kind of URLs would you need to change?

trivial ones that are defined in an external library that the client has no control over, for example, requests to localhost:port.

https://github.com/SAtacker/dapr-sdk-wasi/tree/docker_compose/examples/docker_compose This is the code for reproducing.

The github repository mentioned in the question description also results in this same scenario. However there it is not needed to change any URL

This repository also shows in the README how you can install wasm without Docker Desktop. So that is an option too. Then you can use host network.

Anyway, I gladly accept your suggestion and appreciate it very much. For now, I’ll just make the necessary changes.