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: The image needs to be able to run in AWS Fargate. The above image works there while the latter doesn't, so current answers aren't relevant. I'm probably missing something in /etc, i.e. it's not a Docker configuration issue, since the above image works, but the latter doesn't.
UPDATE2: Copying over /etc from build to websocket-router-rust does not solve the problem. However, replacing scratch with rust:1.63.0-slim-bullseye works. On the other hand, the image is about 700MB using bullseye slim, which is bigger than what I would like as the one based on scratch is 22MB.
CodePudding user response:
I suggest you to pass you DNS addresses to the container at build time.
Here is the Official Guide which explains how to use the --dns
option.
CodePudding user response:
You can set the DNS addresses in /etc/docker/daemon.json
file:
{
"dns": ["10.0.0.2", "8.8.8.8"]
}