docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

Optimize node images removing the content in /tmp folder

Open navarroaxel opened this issue 5 years ago • 3 comments

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/*

navarroaxel avatar Sep 15 '20 11:09 navarroaxel

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

nschonni avatar Sep 15 '20 17:09 nschonni

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.

MichaelLeeHobbs avatar Nov 11 '22 14:11 MichaelLeeHobbs

This issue is now addressed by #2049

PeterDaveHello avatar Apr 08 '24 16:04 PeterDaveHello