Skip to content

Instantly share code, notes, and snippets.

@hatembentayeb
Last active November 10, 2019 03:43
Show Gist options
  • Save hatembentayeb/08d2bb08c8da7579c403c1e5caeff419 to your computer and use it in GitHub Desktop.
Save hatembentayeb/08d2bb08c8da7579c403c1e5caeff419 to your computer and use it in GitHub Desktop.
My Dockerfile for a Rust Project
FROM rustdocker/rust:nightly as cargo-build
RUN apt-get update
RUN apt-get install musl-tools -y
RUN /root/.cargo/bin/rustup target add x86_64-unknown-linux-musl
RUN USER=root /root/.cargo/bin/cargo new --bin material
WORKDIR /material
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
RUN RUSTFLAGS=-Clinker=musl-gcc /root/.cargo/bin/cargo build --release --target=x86_64-unknown-linux-musl --features vendored
RUN rm -f target/x86_64-unknown-linux-musl/release/deps/material*
RUN rm src/*.rs
COPY ./src ./src
RUN RUSTFLAGS=-Clinker=musl-gcc /root/.cargo/bin/cargo build --release --target=x86_64-unknown-linux-musl --features vendored
FROM alpine:latest
COPY --from=cargo-build /auth/target/x86_64-unknown-linux-musl/release/material .
CMD ["./material"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment