Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ jobs:
- name: Test for npm
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} npm --version

- name: Test npm install as a non-root user with an arbitrary UID
run: |
tmp_dir=$(mktemp -d)
chmod 777 "${tmp_dir}"
echo '{"name":"test","version":"1.0.0"}' > "${tmp_dir}/package.json"
docker run --rm --user 1002:1002 -v "${tmp_dir}:/app" -w /app node:${{ matrix.version }}-${{ matrix.variant }} npm install ms@2.1.3

- name: Test npm install with a read-only root filesystem
run: |
tmp_dir=$(mktemp -d)
chmod 777 "${tmp_dir}"
echo '{"name":"test","version":"1.0.0"}' > "${tmp_dir}/package.json"
docker run --rm --user 1002:1002 --read-only --tmpfs /tmp -v "${tmp_dir}:/app" -w /app node:${{ matrix.version }}-${{ matrix.variant }} npm install ms@2.1.3

- name: Test for yarn
if: startsWith(matrix.version, '22') || startsWith(matrix.version, '24') || startsWith(matrix.version, '25')
run: docker run --rm node:${{ matrix.version }}-${{ matrix.variant }} yarn --version
5 changes: 5 additions & 0 deletions 22/alpine3.23/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 22/alpine3.24/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 22/bookworm-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 22/bookworm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 22/trixie-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 22/trixie/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 24/alpine3.23/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 24/alpine3.24/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 24/bookworm-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 24/bookworm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 24/trixie-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 24/trixie/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 26/alpine3.23/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ RUN addgroup -g 1000 node \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 26/alpine3.24/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ RUN addgroup -g 1000 node \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 26/bookworm-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 26/bookworm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 26/trixie-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 26/trixie/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 27/alpine3.23/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ RUN addgroup -g 1000 node \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 27/alpine3.24/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ RUN addgroup -g 1000 node \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 27/bookworm-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 27/bookworm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 27/trixie-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ RUN ARCH= OPENSSL_ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions 27/trixie/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& rm -rf /tmp/*


# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions Dockerfile-alpine.template
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ RUN apk add --no-cache --virtual .build-deps-yarn curl gnupg tar \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions Dockerfile-debian.template
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
5 changes: 5 additions & 0 deletions Dockerfile-slim.template
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ RUN set -ex \
&& yarn --version \
&& rm -rf /tmp/*

# npm's cache defaults to $HOME/.npm, which is not writable when the image
# is run as a user that has no home directory (e.g. an arbitrary --user UID
# on CI runners), see https://github.com/nodejs/docker-node/issues/2495
ENV NPM_CONFIG_CACHE=/tmp/.npm

COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]

Expand Down
13 changes: 13 additions & 0 deletions docs/BestPractices.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Global npm dependencies](#global-npm-dependencies)
- [Handling Kernel Signals](#handling-kernel-signals)
- [Non-root User](#non-root-user)
- [npm cache](#npm-cache)
- [Memory](#memory)
- [CMD](#cmd)
- [Docker Run](#docker-run)
Expand Down Expand Up @@ -118,6 +119,18 @@ RUN deluser --remove-home node \
&& adduser -S -G node -u 999 node
```

## npm cache

The images set `NPM_CONFIG_CACHE=/tmp/.npm` so that npm works when the container runs as a user without a writable home directory — for example an arbitrary `--user` uid on a CI runner, or a Kubernetes pod with `readOnlyRootFilesystem: true` and a writable `/tmp` mounted.

Because the cache lives under `/tmp`, it does not survive container restarts. If you want a persistent cache, point the variable somewhere you control and mount it:

```
docker run -e NPM_CONFIG_CACHE=/usr/src/app/.npm -v npm-cache:/usr/src/app/.npm node npm install
```

Any value you set for `NPM_CONFIG_CACHE` overrides the image default.

## Memory

By default, any Docker Container may consume as much of the hardware such as CPU and RAM. If you are running multiple containers on the same host, you should limit how much memory they can consume.
Expand Down