FROM rust:1.44.1-slim-buster as build-image WORKDIR /usr/src/codebase MAINTAINER Aloïs Micard # Install build dependencies RUN apt-get update && apt-get install -y pkg-config libssl-dev # This is a dummy build to get the dependencies cached. RUN USER=root cargo init COPY Cargo.toml . COPY Cargo.lock . RUN cargo build --release # Build the application COPY . . RUN rm src/main.rs RUN cargo build --release --locked # runtime image FROM debian:buster-slim WORKDIR /app MAINTAINER Aloïs Micard # Install runtime dependencies RUN apt-get update && apt-get install -y libssl1.1 COPY --from=build-image /usr/src/codebase/target/release/codebase . ENTRYPOINT ["./codebase"]