Docker container in host network is not reachable on ports

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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" ]
</code>
<code>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" ] </code>
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/usr/bin/env sh
dbus-daemon --system
avahi-daemon --no-chroot &
/usr/bin/snapserver $EXTRA_ARGS
</code>
<code>#!/usr/bin/env sh dbus-daemon --system avahi-daemon --no-chroot & /usr/bin/snapserver $EXTRA_ARGS </code>
#!/usr/bin/env sh

dbus-daemon --system
avahi-daemon --no-chroot &
/usr/bin/snapserver $EXTRA_ARGS

snapserver.conf used by Dockerfile

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[stream]
source = tcp://0.0.0.0?name=Snapserver
[http]
doc_root = /usr/share/snapserver/snapweb
</code>
<code>[stream] source = tcp://0.0.0.0?name=Snapserver [http] doc_root = /usr/share/snapserver/snapweb </code>
[stream]
source = tcp://0.0.0.0?name=Snapserver

[http]
doc_root = /usr/share/snapserver/snapweb

docker-compose.yml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>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
</code>
<code>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 </code>
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

  1. Build the image using my Dockerfile (remembre to tag accordingly and change dockerfile to use correct image)
  2. Start the container using my docker-compose.yml
  3. The WebUI should be reachable on your-ip:1780 but it isn’t for me

Any help is appreciated, thank you!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật