1
0
mirror of https://github.com/actix/examples synced 2025-06-28 18:00:37 +02:00

update docker sample

This commit is contained in:
Rob Ede
2022-01-27 02:58:13 +00:00
parent 6e34f07fbf
commit d327e8800b
5 changed files with 887 additions and 1090 deletions

View File

@ -1,24 +1,38 @@
FROM rust:1-slim-buster AS base
ENV USER=root
# NB: This is not a production-grade Dockerfile.
#################
## build stage ##
#################
FROM rust:1-slim-bullseye AS builder
WORKDIR /code
RUN cargo init
COPY Cargo.toml /code/Cargo.toml
# 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
COPY src /code/src
# copy app files
COPY src src
CMD [ "cargo", "test", "--offline" ]
# compile app
RUN cargo build --release
FROM base AS builder
###############
## run stage ##
###############
FROM debian:bullseye-slim
WORKDIR /app
RUN cargo build --release --offline
# copy server binary from build stage
COPY --from=builder /code/target/release/docker_sample docker_sample
FROM debian:buster-slim
# set user to non-root unless root is required for your app
USER 1001
COPY --from=builder /code/target/release/docker_sample /usr/bin/docker_sample
# indicate what port the server is running on
EXPOSE 8080
EXPOSE 5000
ENTRYPOINT [ "/usr/bin/docker_sample" ]
# run server
CMD [ "/app/docker_sample" ]