Created
August 6, 2020 15:19
-
-
Save Type1J/e1b6a7706c2f5ee841ce3bd6d4f6f456 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
RUN cargo install --path . --color always 2>&1 | |
FROM alpine:3.12 as runner | |
COPY --from=builder /usr/local/cargo/bin/your_web_app_exe_name /usr/local/bin/your_web_app_exe_name | |
RUN addgroup -S appgroup && adduser -S appuser -G appgroup | |
USER appuser | |
ENV PORT 8000 | |
CMD ["your_web_app_exe_name"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment