FROM rust:1.85-slim-bookworm AS build # create a new empty shell project RUN USER=root cargo new --bin http_server WORKDIR /http_server # copy over your manifests COPY ./Cargo.lock ./Cargo.lock COPY ./Cargo.toml ./Cargo.toml # this build step will cache your dependencies RUN cargo build --release RUN rm src/*.rs # copy your source tree COPY ./src ./src # build for release as a static-pie linked binary RUN rm ./target/release/deps/http_server* ENV RUSTFLAGS='-C target-feature=+crt-static' RUN cargo build --release --target x86_64-unknown-linux-gnu FROM scratch # copy the build artifact from the build stage COPY --from=build /http_server/target/x86_64-unknown-linux-gnu/release/http_server / COPY ./www /www EXPOSE 8080 CMD ["/http_server"]