Docker image size reduction
authorCode-Otto <redacted>
Tue, 26 Mar 2024 19:48:58 +0000 (20:48 +0100)
committerCode-Otto <redacted>
Tue, 26 Mar 2024 19:48:58 +0000 (20:48 +0100)
- Use the python:3.11-alpine3.19 image as runtime container base
- Replace gosu with su-exec
- Clean pip and pipenv package cache

Dockerfile
entrypoint.sh

index df9c15f2710f87d1d1b7dbf8eff8b93dafe228d7..e71b1023beb93d3e0fbdeeeb6bed14489a12e253 100644 (file)
@@ -17,7 +17,7 @@ COPY client ./client
 RUN npm run build
 
 # Runtime Container
-FROM python:3.11-slim-bullseye
+FROM python:3.11-alpine3.19
 
 ARG BUILD_DIR
 
@@ -30,17 +30,15 @@ ENV FLATNOTES_PATH=/data
 RUN mkdir -p ${APP_PATH}
 RUN mkdir -p ${FLATNOTES_PATH}
 
-RUN apt update && apt install -y \
-    curl \
-    gosu \
-    && rm -rf /var/lib/apt/lists/*
+RUN apk add --no-cache su-exec curl
 
-RUN pip install pipenv
+RUN pip install --no-cache-dir pipenv
 
 WORKDIR ${APP_PATH}
 
 COPY LICENSE Pipfile Pipfile.lock ./
-RUN pipenv install --deploy --ignore-pipfile --system
+RUN pipenv install --deploy --ignore-pipfile --system && \
+    pipenv --clear
 
 COPY server ./server
 COPY --from=build ${BUILD_DIR}/client/dist ./client/dist
index dc810f3cf41551504f1e90dd6ca7b6564206a7c2..30a5bad4d6f634b5241262a2bc8c2a968abea64a 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 set -e
 
@@ -31,7 +31,7 @@ if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then
     chown -R ${PUID}:${PGID} ${FLATNOTES_PATH}
 
     echo Starting flatnotes as user ${PUID}...
-    exec gosu ${PUID}:${PGID} ${flatnotes_command}
+    exec su-exec ${PUID}:${PGID} ${flatnotes_command}
       
 else
     echo "A user was set by docker, skipping file permission changes."
git clone https://git.99rst.org/PROJECT