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:
- Running the binary and
avahi-browse
on the host:
./server
Yields:
avahi-browse -all
+ enp5s0 IPv6 asto-dnssd _rust._tcp local
- 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
- Running the binary in a subshell after starting
dbus
andavahi-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"]
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:
But this does: