Created
May 27, 2019 01:12
-
-
Save jamesproud/4022da405709a633ba7f021a36d7b462 to your computer and use it in GitHub Desktop.
Rust Dockerfile
This file contains hidden or 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
| # Cargo Build Stage | |
| #FROM rust:1.35 as build | |
| FROM rust@sha256:9fcf1c9d04e10f1c882041da280e3466a5d6f57b27f4cfd8b1ff06f34419ed36 as build | |
| RUN apt-get update | |
| RUN apt-get install musl-tools -y | |
| RUN rustup target add x86_64-unknown-linux-musl | |
| WORKDIR /usr/src/myapp | |
| COPY Cargo.toml Cargo.toml | |
| RUN mkdir src/ | |
| RUN echo "fn main() {println!(\"If you see this, the build broke\")}" > src/main.rs | |
| RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl | |
| RUN rm -f target/x86_64-unknown-linux-musl/release/deps/myapp* | |
| COPY . . | |
| RUN RUSTFLAGS=-Clinker=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl | |
| # Final Stage | |
| #FROM alpine:3.9.4 | |
| FROM alpine@sha256:769fddc7cc2f0a1c35abb2f91432e8beecf83916c421420e6a6da9f8975464b6 | |
| RUN addgroup -g 1000 myapp | |
| RUN adduser -D -s /bin/sh -u 1000 -G myapp myapp | |
| WORKDIR /home/myapp/bin/ | |
| COPY --from=build /usr/src/myapp/target/x86_64-unknown-linux-musl/release/myapp . | |
| RUN chown myapp:myapp myapp | |
| USER myapp | |
| EXPOSE 8080 | |
| ENTRYPOINT ["./myapp"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment