Skip to content

Instantly share code, notes, and snippets.

@cbzehner
Created February 26, 2020 07:36
Show Gist options
  • Save cbzehner/d6419589ac1345b0532d197406796c03 to your computer and use it in GitHub Desktop.
Save cbzehner/d6419589ac1345b0532d197406796c03 to your computer and use it in GitHub Desktop.
Rocket Dockerfile
FROM rustlang/rust:nightly
MAINTAINER "cbzehner@gmail.com"
ENV BUILD_DIR=/usr/src/<app_name>
RUN mkdir -p $BUILD_DIR
WORKDIR $BUILD_DIR
# TODO: Confirm this is actually needed to run `diesel setup`
# RUN cargo install diesel_cli --no-default-features --features postgres
# Cache the cargo build process using the Docker cache
# For details see "Fixing the docker cache utilization" (https://blog.sedrik.se/posts/my-docker-setup-for-rust/)
COPY Cargo.toml Cargo.lock rust-toolchain ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo test
RUN cargo build
COPY . .
RUN echo "Current directory: `pwd`" \
&& echo "Directory contents: " && ls \
&& echo "Add files to .dockerignore to exclude them"
# Touch the real main.rs file or else Docker will use the cached one
RUN touch src/main.rs
RUN cargo build
EXPOSE 8000
ENTRYPOINT ["./target/debug/<app_name>"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment