I Don't Know Why Docker Desktop "--network host" is not working and "/dev/snd" is not found.

Docker Engine VS Docker Desktop Spide Man Meme
???

I'm entirely new to the Docker container world. So, here are my first and last unsolve questions. First, why "--network host" is not working? Lastly, why does "--device /dev/snd" always show the error message "no such file or directory"?

Here is a little context. My computer is running Linux Mint 21.1 OS and using Docker Desktop. The images I want to run on the container are Home Assistant and Shairport-Sync.

Host network mode acts differently in Docker Engine and Docker Desktop.

I follow the official Home Assistant installation guide to set up and run the Home Assistant container.

The command:

docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=Asia/Kuala_Lumpur \
  -v /home/juan/documents/docker:/config \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

Everything seems to work well. But I can't access the Home Assistant web UI. I got no error messages from the Docker or inside the Docker container.

I find some possible solutions from Google, so let's discuss them:

  • Publishing a container's port to the host(-p <port>:<port>)

    Publishing a specific container's port to the host is not the solution for Home Assistant. This method worked at first. I can access the web UI with the 8123 port. But it will block the Home Assistant discovery function, causing no device on the same network can add to Home Assistant.

  • Block by Firewall

    Someones suggest adding a new rule to the firewall that allows any traffic to pass through. When I check the UFW firewall status, it shows inactive. So, I don't think the firewall is the root cause.

  • Different IP Address.

    I tried several IP addresses with port 8123, but no luck with any of them.

    Example:

    • 192.168.0.125:8123(My laptop's IP address)
    • 127.0.0.1/localhost:8123
    • homeassistant.local:8123
    • homeassistant:8123
    • 192.168.56.4/192.168.56.5:8123(Container's IP address).

After some digging, I find some clues that may explain this issue. The Docker Desktop is a virtual machine(VM) that runs the containers. When I add the "--network host" option to the command, it shares the VM network with the container.

References: [1] [2] (**This is my understanding. I may be wrong. Please feel free to correct me)

Docker Desktop needs sound device access.

For the Shairport-Sync, I try to pass the sound devices to the container with the "--device /dev/snd" option.

""/dev/snd": no such file or directory." error message from Docker Desktop.
""/dev/snd": no such file or directory." error message from Docker Desktop.

The command:

  docker run -d \
    --name Shairport-Sync \
    --restart unless-stopped \
    --net host --device /dev/snd \
    mikebrady/shairport-sync

The Docker Desktop creates the container but comes with a "no such file or directory" error message. As I mentioned above, the Docker Desktop runs a VM. The VM doesn't have the OS "/dev/snd" folder access. So, the error message seems reasonable here.

Ditch Docker Desktop and get Docker Engine.

My solution is to uninstall the Docker Desktop immediately and download the Docker Engine.

After the Docker Engine installation, I run the docker commands to install Home Assistant and Shairport-Sync. Both commands execute smoothly. I can access the Home Assistant's web UI without any problem. The Shairport-Sync can access the sound device but have a different problem.

I think I will learn how to fix the issues on Docker Desktop later. But now, Docker Engine works for me.

Next Post Previous Post
No Comment
Add Comment
comment url