Problem
I am running a docker container (snapcast server) and need to run it in host mode.
Before I ran it in host mode I forwarded ports 1704, 1705 and 1780 (where the Web UI is reachable on port 1780) in my docker-compose.yml and everything worked when doing it like that.
When I changed my docker-compose to use network_mode: host
the container started as expected and logs looked normal.
However the Web UI is not reachable (and connections via the other ports cannot be made).
What I did / what my understanding is
As far as I understood a docker container in network_mode:host
is running directly on the host container and thus uses the ports of the host directly wihtout any port mappings so I expected to be able to reach the container just like I did when it ran normally (as I mapped port 1705:1705 and so on).
I tried to look at the open ports using netstat -tunlp
, when I do that I see that a TCP listening on all three ports is active which is why I really do not understand why this does not work.
Netstat output:
tcp 0 0 0.0.0.0:1780 0.0.0.0:* LISTEN 4132631/snapserver
tcp 0 0 0.0.0.0:1704 0.0.0.0:* LISTEN 4132631/snapserver
tcp 0 0 0.0.0.0:1705 0.0.0.0:* LISTEN 4132631/snapserver
So I have a container that seems to start normally and a “confirmation” that there is active listening on the ports I need yet I cannot make a connection.
Furthermore I have trid to do the same with another container. When I changed the compose file to use network_mode: host
and restarted the container it was reachable just like it was before so I do not think that it is a docker config problem.
Resources needed for reproduction
Dockerfile
FROM alpine:edge AS builder
WORKDIR /snapcast
RUN apk add npm curl alpine-sdk
RUN npm install --silent --save-dev -g [email protected]
RUN wget https://github.com/badaix/snapweb/archive/refs/tags/v0.7.0.tar.gz
RUN tar xzf v0.7.0.tar.gz --directory /
WORKDIR /snapweb-0.7.0
RUN npm ci
RUN npm run build
FROM alpine:edge
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories
RUN echo "https://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories
RUN apk add --no-cache gdb librespot snapcast dbus avahi avahi-compat-libdns_sd
COPY --from=builder /snapweb-0.7.0/dist /usr/share/snapserver/snapweb
COPY snapserver.conf /etc/snapserver.conf
COPY startup.sh startup.sh
RUN chmod +x ./startup.sh
EXPOSE 1704 1705 1780
ENTRYPOINT [ "./startup.sh" ]
startup.sh used by Dockerfile
#!/usr/bin/env sh
dbus-daemon --system
avahi-daemon --no-chroot &
/usr/bin/snapserver $EXTRA_ARGS
snapserver.conf used by Dockerfile
[stream]
source = tcp://0.0.0.0?name=Snapserver
[http]
doc_root = /usr/share/snapserver/snapweb
docker-compose.yml
version: '3'
services:
snapserver:
image: tiko/snapcastserver:latest
container_name: snapserver
restart: unless-stopped
network_mode: host
volumes:
- /root/snapcastserver/snapserver.conf:/etc/snapserver.conf
Reproduction steps
- Build the image using my
Dockerfile
(remembre to tag accordingly and change dockerfile to use correct image) - Start the container using my
docker-compose.yml
- The WebUI should be reachable on
your-ip:1780
but it isn’t for me
Any help is appreciated, thank you!