Skip to content

Build your personal knowledge base with Trilium Notes

build(Docker): improve image size, by deleting node-compile-cache

Panagiotis Papadopoulos70e227f4c3b7
diff --git a/Dockerfile b/Dockerfile
index c21d9f4f6c..2436a8124f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,7 +14,9 @@ RUN npm ci && \
mv dist/* \
start-docker.sh \
/usr/src/app/ && \
- rm -rf /usr/src/app/build
+ rm -rf \
+ /usr/src/app/build \
+ /tmp/node-compile-cache
#TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work
# currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down),
@@ -29,14 +31,16 @@ WORKDIR /usr/src/app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gosu && \
- rm -rf /var/lib/apt/lists/* && \
- rm -rf /var/cache/apt/*
+ rm -rf \
+ /var/lib/apt/lists/* \
+ /var/cache/apt/*
COPY --from=builder /usr/src/app ./
RUN sed -i "/electron/d" package.json && \
npm ci --omit=dev && \
- npm cache clean --force
+ npm cache clean --force && \
+ rm -rf /tmp/node-compile-cache
# Configure container
EXPOSE 8080
diff --git a/Dockerfile.alpine b/Dockerfile.alpine
index 09efe25294..9370bd6da4 100644
--- a/Dockerfile.alpine
+++ b/Dockerfile.alpine
@@ -14,7 +14,9 @@ RUN npm ci && \
mv dist/* \
start-docker.sh \
/usr/src/app/ && \
- rm -rf /usr/src/app/build
+ rm -rf \
+ /usr/src/app/build \
+ /tmp/node-compile-cache
#TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work
# currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down),
@@ -32,7 +34,8 @@ COPY --from=builder /usr/src/app ./
RUN sed -i "/electron/d" package.json && \
npm ci --omit=dev && \
- npm cache clean --force
+ npm cache clean --force && \
+ rm -rf /tmp/node-compile-cache
# Add application user
RUN adduser -s /bin/false node; exit 0