nodejs / docker-node

Official Docker Image for Node.js :whale: :turtle: :rocket:
https://hub.docker.com/_/node/
MIT License
8.27k stars 1.97k forks source link

Optimize node images removing the content in /tmp folder #1326

Open navarroaxel opened 4 years ago

navarroaxel commented 4 years ago

Analyzing the docker layers of node:latest, node:slim and node:alpine images using dive

I found that the Yarn installation adds a /tmp/v8-compile-cache-0 with a size 2.2MiB in all these images and this is not needed for the users of theses images.

node:alpine Screenshot_20200915_080820 node:slim Screenshot_20200915_081850 node:latest Screenshot_20200915_081412

Also, the /var/cache and /var/log folders sounds useless.

Let me know if I can help submitting a PR with

rm -rf /tmp/*
nschonni commented 4 years ago

There is an open PR for some of this over here https://github.com/nodejs/docker-node/pull/1283

MichaelLeeHobbs commented 2 years ago

Not to be rude but why has this not been addressed? To be clear there is nothing the downstream users can do within the standard docker framework to clear tmp of the previous layers even with squash which is still considered experimental.

RUN npm install --omit=dev \
    && npm cache clean --force \
    && rm -rf /tmp/* \
    && rm -rf node_modules/@aws-sdk/client-ec2/dist-types \
    && rm -rf node_modules/@aws-sdk/client-ec2/dist-es \
    && rm -rf node_modules/@types \
    && ls -al /tmp # empty as expected
docker build -t jaspermanager-server . --squash --progress=plain

Inspecting the image still shows /tmp/v8-compile-cache-0

In many ways, this relates to other issues like #777. When you are dealing with slow networks every byte counts.

PeterDaveHello commented 7 months ago

This issue is now addressed by #2049