💾 Archived View for ibannieto.info › gemlog › 2022-12-06.gmi captured on 2023-05-24 at 17:40:40. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-03-20)
-=-=-=-=-=-=-
This is the Dockerfile that I'm currently using when I need to create some proof of concepts with rust.
In this case, I'm building a simple rust application using the rocket framework as dependency.
There are two stages, the first one is for get the crates and build the final binary application file.
The second one is for running the application and discarding the previous stage, saving lots of storage.
Please adjust your requirements in order to use this Dockerfile in your projects.
FROM rust:1.61.0-slim as builder WORKDIR /usr/src RUN USER=root cargo new hello-rocket COPY Cargo.toml Cargo.lock /usr/src/hello-rocket/ WORKDIR /usr/src/hello-rocket RUN rustup target add x86_64-unknown-linux-musl RUN cargo build --target x86_64-unknown-linux-musl --release COPY src /usr/src/hello-rocket/src/ RUN touch /usr/src/hello-rocket/src/main.rs RUN cargo build --target x86_64-unknown-linux-musl --release FROM alpine:3.16.0 AS runtime COPY --from=builder /usr/src/hello-rocket/target/x86_64-unknown-linux-musl/release/hello-rocket /usr/local/bin EXPOSE 8000 CMD ["/usr/local/bin/hello-rocket"]
This one is already tested and works flawlessly but don't use it in production!