Skip to content

Instantly share code, notes, and snippets.

@Type1J
Type1J / Dockerfile
Created August 6, 2020 15:19
Build (with Cargo) and run a statically linked (to run on Alpine Linux) web app written in Rust with Docker with no dependency rebuilds on further `docker build` commands. I hope this helps somebody.
FROM rust:1.45-alpine as builder
WORKDIR /usr/src/app
RUN apk add --no-cache musl-dev
RUN USER="builder" cargo init
COPY Cargo.toml .
COPY Cargo.lock .
RUN mkdir .cargo && cargo vendor > .cargo/config
RUN cargo build --release --color always 2>&1
COPY ./src src
RUN touch src/main.rs && cargo build --release --color always 2>&1