Skip to content

Instantly share code, notes, and snippets.

@ArinFaraj
Last active January 19, 2023 11:09
Show Gist options
  • Select an option

  • Save ArinFaraj/9380f62155f463c02a651f60f888390d to your computer and use it in GitHub Desktop.

Select an option

Save ArinFaraj/9380f62155f463c02a651f60f888390d to your computer and use it in GitHub Desktop.
Good enough rust + actix web dockerfile [replace the APP_NAME]
target
Dockerfile
.dockerignore
.git
.gitignore
.env
FROM rust:1.66.1 as builder
WORKDIR /usr/src
RUN USER=root cargo new docker-app
COPY Cargo.toml Cargo.lock /usr/src/docker-app/
WORKDIR /usr/src/docker-app
RUN cargo build --release
# Now copy in the rest of the sources
COPY src /usr/src/docker-app/src/
## Touch main.rs to prevent cached release build
RUN touch /usr/src/docker-app/src/main.rs
# This is the actual application build.
RUN cargo build --release
FROM gcr.io/distroless/cc-debian11
# Copy application binary from builder image
COPY --from=builder /usr/src/docker-app/target/release/[APP_NAME] /usr/local/bin/
COPY .env.example /usr/local/bin/.env
EXPOSE 3030
# Run the application
CMD ["/usr/local/bin/[APP_NAME]"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment