Skip to content

Instantly share code, notes, and snippets.

@terry90
Last active February 5, 2022 16:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save terry90/cbb5337335d3252146ef92b62969f83d to your computer and use it in GitHub Desktop.
Save terry90/cbb5337335d3252146ef92b62969f83d to your computer and use it in GitHub Desktop.
Rust Dockerfile to build really small containers with postgres and SSL (~20Mo with rocket and diesel). Dependencies are cached for faster builds.
FROM clux/muslrust as build
WORKDIR /app/
# Deps caching begins
COPY Cargo.toml .
COPY Cargo.lock .
RUN mkdir src
RUN echo "fn main() {}" > src/main.rs
RUN apt-get update && apt-get install -y pkg-config libssl-dev libpq-dev && apt-get clean
RUN cargo build --release
# Deps caching ends
COPY . .
RUN touch src/main.rs
RUN cargo build --release
FROM alpine
WORKDIR /app/
COPY --from=build app/target/x86_64-unknown-linux-musl/release/project ./
ENV ROCKET_ENV prod
CMD ["./project"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment