Skip to content

Instantly share code, notes, and snippets.

@digizeph
Created June 18, 2021 16:57
Show Gist options
  • Save digizeph/f252202875fc8cea3aabc1d43106574c to your computer and use it in GitHub Desktop.
Save digizeph/f252202875fc8cea3aabc1d43106574c to your computer and use it in GitHub Desktop.
Two-stage build for Rust project with need for ssl libraries (such as an web api)
LABEL maintainer="YOUR NAME <YOUR@EMAIL>"
# select build image
FROM rust:1.52 as build
# create a new empty shell project
RUN USER=root cargo new --bin my_project
WORKDIR /my_project
# if you need nightly
# change toolchain to nightly for rocket
# RUN rustup default nightly
# build for release
COPY ./Cargo.toml ./Cargo.toml
COPY ./src ./src
RUN cargo build --release
# our final base
FROM debian:buster-slim
RUN DEBIAN=NONINTERACTIVE apt update; apt install -y libssl-dev libpq-dev ca-certificates tzdata; rm -rf /var/lib/apt/lists/*
# copy the build artifact from the build stage
COPY --from=build /my_project/target/release/YOUR_PROGRAM /usr/local/bin/YOUR_PROGRAM
# set the startup command to run your binary
CMD ["YOUR_PROGRAM"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment