# Create a new empty shell project
RUN USER=root cargo new --bin myapp
WORKDIR /myapp
# Copy the manifests
COPY Cargo.toml Cargo.lock ./
# Copy source code and build it in release mode
COPY src ./src
RUN cargo build --release
# Stage 2: Create the runtime image
FROM debian:buster-slim
# Install necessary packages
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy the compiled binary from the builder stage
COPY --from=builder /myapp/target/release/myapp /usr/local/bin/myapp
# Expose the port specified by the environment variable
ENV PORT 8080
EXPOSE ${PORT}
# Set the binary as the entry point
CMD ["myapp"]