2022-01-27 03:58:13 +01:00
|
|
|
# NB: This is not a production-grade Dockerfile.
|
2020-02-24 18:48:04 +01:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
#################
|
|
|
|
## build stage ##
|
|
|
|
#################
|
2024-02-05 17:26:50 +01:00
|
|
|
FROM rust:1-slim-bookworm AS builder
|
2020-05-27 22:01:26 +02:00
|
|
|
WORKDIR /code
|
2020-02-24 18:48:04 +01:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# Download crates-io index and fetch dependency code.
|
|
|
|
# This step avoids needing to spend time on every build downloading the index
|
|
|
|
# which can take a long time within the docker context. Docker will cache it.
|
|
|
|
RUN USER=root cargo init
|
|
|
|
COPY Cargo.toml Cargo.toml
|
|
|
|
RUN cargo fetch
|
2020-02-24 18:48:04 +01:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# copy app files
|
|
|
|
COPY src src
|
2020-02-24 18:48:04 +01:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# compile app
|
|
|
|
RUN cargo build --release
|
2020-05-27 22:01:26 +02:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
###############
|
|
|
|
## run stage ##
|
|
|
|
###############
|
2024-02-05 17:26:50 +01:00
|
|
|
FROM bitnami/minideb:bookworm
|
2022-01-27 03:58:13 +01:00
|
|
|
WORKDIR /app
|
2020-05-27 22:01:26 +02:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# copy server binary from build stage
|
|
|
|
COPY --from=builder /code/target/release/docker_sample docker_sample
|
2020-05-27 22:01:26 +02:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# set user to non-root unless root is required for your app
|
|
|
|
USER 1001
|
2020-02-24 18:48:04 +01:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# indicate what port the server is running on
|
|
|
|
EXPOSE 8080
|
2020-02-24 18:48:04 +01:00
|
|
|
|
2022-01-27 03:58:13 +01:00
|
|
|
# run server
|
|
|
|
CMD [ "/app/docker_sample" ]
|