Challenged accessing containerized DNS-SD

197 views Asked by At

I'm a ZeroConf (and Rust) noob and I'm struggling to understand why I'm unable to access a service based upon the astro-dnssd example when the code is containerized and run in a subshell.

The following work:

  1. Running the binary and avahi-browse on the host:
./server

Yields:

avahi-browse -all
+ enp5s0 IPv6 asto-dnssd                                    _rust._tcp           local
  1. Running the binary in the container manually and avahi-browse on the host:
docker run .... --entrypoint=bash [[image]]
> service dbus start
> service avahi-daemon start
> ./service

And:

+ docker0 IPv4 asto-dnssd                                    _rust._tcp           local
  1. Running the binary in a subshell after starting dbus and avahi-daemon:
docker run .... --entrypoint=bash [[image]]
> service dbus start
> service avahi-daemon start
> bash -c "./service"

But, if I start the services in the subshell and run the binary, nothing:

docker run .... --entrypoint=bash [[image]]
> bash -c "service dbus start && service avahi-daemon start && ./service"

Why would this be?

I have another example using the zeronconf crate and this works fine this way.

IIUC I must start dbus and avahi-daemon in the container image before the server and using a subshell is the correct (!?) approach:

ARG PROJECT=astro-dnssd

FROM rustlang/rust:nightly-slim as builder

ARG PROJECT

RUN apt update && \
    apt install -y libavahi-compat-libdnssd-dev

RUN USER=root cargo new --bin ${PROJECT}

WORKDIR /${PROJECT}

COPY ./Cargo.toml ./Cargo.toml
RUN cargo build --release
RUN rm src/*.rs

ADD . ./

# Replace hyphens with underscores in ${PROJECT}
RUN rm ./target/release/deps/$(echo ${PROJECT} | tr '-' '_')*

RUN cargo build --release


FROM debian:buster-slim as runtime

ARG PROJECT

WORKDIR /bin

# Copy from builder and rename to 'server'
COPY --from=builder /${PROJECT}/target/release/${PROJECT} ./server

RUN apt update \
    && apt install -y \
    libavahi-compat-libdnssd-dev \
    && rm -rf /var/lib/apt/lists/*

RUN mkdir -p /var/run/dbus

ENTRYPOINT ["bash", "-c", "service dbus start && service avahi-daemon start && ./server"]
1

There are 1 answers

0
DazWilkin On

Solved: timing.

If I add a sleep between the service starting, this appears to give the system time to work correctly:

This doesn't work:

(
  service dbus start
  service avahi-daemon start
  /release/astro-dnssd
)

But this does:

(
  service dbus start
  service avahi-daemon start
  sleep 2s
  /release/astro-dnssd
)