I have a Rust program that needs to do some DNS lookups. It works just fine with the following Dockerfile:
FROM rust:1.63.0-bullseye AS build
WORKDIR /app
COPY . .
RUN cargo build --release
EXPOSE 8080
ENTRYPOINT ["/app/target/release/router"]
I've tried to create a somewhat minimalistic image for the program like so:
FROM rust:1.63.0-bullseye AS build
WORKDIR /app
COPY . .
RUN cargo build --release
RUN mkdir -p /app/lib
RUN cp -LR $(ldd ./target/release/router | grep "=>" | cut -d ' ' -f 3) /app/lib
FROM scratch AS websocket-router-rust
WORKDIR /app
COPY --from=build /app/lib /app/lib
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=build /app/target/release/router /app/router
ENV LD_LIBRARY_PATH=/app/lib
EXPOSE 8080
ENTRYPOINT ["/app/router"]
However, DNS lookups seem to fail when using the latter Dockerfile. Any ideas what files could be missing that should be copied from the build stage?
UPDATE: Got it working by running a file access tracer inside the Docker image while making a request to the server and then copying over all the files that were read with COPY --from... The Dockerfile got a bit messy, but it's less than 30MB now. The main problem was that ldd doesn't return libnss SOs, so those were missing from the image.