Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cargo chef from Dockerfile #1

Open
manuelmauro opened this issue Feb 6, 2024 · 0 comments
Open

Remove cargo chef from Dockerfile #1

manuelmauro opened this issue Feb 6, 2024 · 0 comments

Comments

@manuelmauro
Copy link
Owner

Use something like this:

# Use the official Rust image as the base image
FROM rust:latest as builder

# Create a new empty shell project
RUN USER=root cargo new --bin app
WORKDIR /app

# Copy our manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# This build step will cache your dependencies
RUN cargo build --release
RUN rm src/*.rs

# Now that the dependencies are built, copy your source code
COPY ./src ./src

# Build for release.
# Touch the main file to force recompilation of the source code (in case it was changed)
RUN touch src/main.rs && cargo build --release

# The final stage, which copies the binary from the "builder" stage and reduces the final image size
FROM debian:buster-slim
COPY --from=builder /app/target/release/your-app-name .

# Set the command to run your binary
CMD ["./your-app-name"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant