From 2b2bd8421b0d03cfe74d2029694cf4b4d82ffbde Mon Sep 17 00:00:00 2001 From: Basti Date: Wed, 24 Feb 2021 20:17:36 +0100 Subject: [PATCH] Added multi-staged container build and a user (#134) * Added multi-staged container build and a user This reduces the image size from 2Gb to 92Mb by only put the necessary files into the container. Container now runs without root priviliges. * Add EXPOSE to Dockerfile --- Dockerfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 63b191a..6b4cdcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,17 @@ -FROM rust:latest +FROM rust:latest as builder WORKDIR /usr/src/libreddit COPY . . - RUN cargo install --path . + +FROM debian:buster-slim + +RUN apt-get update && apt-get install -y libcurl4 && rm -rf /var/lib/apt/lists/* +COPY --from=builder /usr/local/cargo/bin/libreddit /usr/local/bin/libreddit +RUN useradd --system --user-group --home-dir /nonexistent --no-create-home --shell /usr/sbin/nologin libreddit +USER libreddit + +EXPOSE 8080 + CMD ["libreddit"]