我是 ZeroConf(和 Rust)菜鸟,我很难理解为什么astro-dnssd
当代码被容器化并在子 shell 中运行时,我无法访问基于示例的服务。
以下工作:
avahi-browse
在主机上运行二进制文件:
./server
产量:
avahi-browse -all
+ enp5s0 IPv6 asto-dnssd _rust._tcp local
avahi-browse
在容器中和主机上手动运行二进制文件:
docker run .... --entrypoint=bash [[image]]
> service dbus start
> service avahi-daemon start
> ./service
和:
+ docker0 IPv4 asto-dnssd _rust._tcp local
dbus
启动和后在子shell中运行二进制文件avahi-daemon
:
docker run .... --entrypoint=bash [[image]]
> service dbus start
> service avahi-daemon start
> bash -c "./service"
但是,如果我在子 shell 中启动服务并运行二进制文件,则什么也没有:
docker run .... --entrypoint=bash [[image]]
> bash -c "service dbus start && service avahi-daemon start && ./service"
为什么会这样?
我有另一个使用zeronconf
板条箱的例子,这样可以正常工作。
IIUC 我必须在服务器之前启动容器映像dbus
并使用子shell 是正确的(!?)方法:avahi-daemon
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"]