0

我是 ZeroConf(和 Rust)菜鸟,我很难理解为什么astro-dnssd当代码被容器化在子 shell 中运行时,我无法访问基于示例的服务。

以下工作:

  1. avahi-browse在主机上运行二进制文件:
./server

产量:

avahi-browse -all
+ enp5s0 IPv6 asto-dnssd                                    _rust._tcp           local
  1. avahi-browse在容器中和主机上手动运行二进制文件:
docker run .... --entrypoint=bash [[image]]
> service dbus start
> service avahi-daemon start
> ./service

和:

+ docker0 IPv4 asto-dnssd                                    _rust._tcp           local
  1. 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"]
4

1 回答 1

0

解决:时间。

如果我sleep在服务启动之间添加一个,这似乎可以让系统有时间正常工作:

这不起作用:

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

但这确实:

(
  service dbus start
  service avahi-daemon start
  sleep 2s
  /release/astro-dnssd
)
于 2020-11-30T18:41:30.840 回答