1
0
mirror of https://github.com/actix/examples synced 2024-11-30 09:12:54 +01:00
examples/docker/Dockerfile

39 lines
879 B
Docker
Raw Normal View History

2022-01-27 03:58:13 +01:00
# NB: This is not a production-grade Dockerfile.
2022-01-27 03:58:13 +01:00
#################
## build stage ##
#################
FROM rust:1-slim-bookworm AS builder
WORKDIR /code
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
2022-01-27 03:58:13 +01:00
# copy app files
COPY src src
2022-01-27 03:58:13 +01:00
# compile app
RUN cargo build --release
2022-01-27 03:58:13 +01:00
###############
## run stage ##
###############
FROM bitnami/minideb:bookworm
2022-01-27 03:58:13 +01:00
WORKDIR /app
2022-01-27 03:58:13 +01:00
# copy server binary from build stage
COPY --from=builder /code/target/release/docker_sample docker_sample
2022-01-27 03:58:13 +01:00
# set user to non-root unless root is required for your app
USER 1001
2022-01-27 03:58:13 +01:00
# indicate what port the server is running on
EXPOSE 8080
2022-01-27 03:58:13 +01:00
# run server
CMD [ "/app/docker_sample" ]