-- Leo's gemini proxy

-- Connecting to ibannieto.info:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini;lang=en

Creating slim container images for rust


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!


Creating slim container images for rust was published on 📅 2022-12-06


back


CC-BY-SA 4.0

-- Response ended

-- Page fetched on Tue May 21 21:14:52 2024