Skip to content

Commit b466ecf

Browse files
authored
docs: add instructions to upgrade npm (#2579)
1 parent 61ee0d1 commit b466ecf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

docs/BestPractices.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
## Table of Contents
77

88
- [Environment Variables](#environment-variables)
9+
- [Upgrading npm](#upgrading-npm)
910
- [Global npm dependencies](#global-npm-dependencies)
1011
- [Handling Kernel Signals](#handling-kernel-signals)
1112
- [Non-root User](#non-root-user)
@@ -27,6 +28,25 @@ Run with `NODE_ENV` set to `production`. This is the way you would pass in secre
2728
-e "NODE_ENV=production"
2829
```
2930

31+
## Upgrading npm
32+
33+
Each `node` Docker image includes npm, bundled with Node.js.
34+
You can check the version from the CLI, for example:
35+
36+
```shell
37+
docker run --rm --entrypoint npm node:lts --version
38+
```
39+
40+
The bundled npm version is also listed in the detail information on the
41+
[Node.js Releases](https://nodejs.org/en/about/previous-releases) page.
42+
If you need to upgrade (or downgrade) the version of npm,
43+
add the following to your `Dockerfile`, replacing `<version>` with the desired value.
44+
View the [npm registry listing](https://www.npmjs.com/package/npm?activeTab=versions) for available versions and tags.
45+
46+
```Dockerfile
47+
RUN npm install --global npm@<version>
48+
```
49+
3050
## Global npm dependencies
3151

3252
If you need to install global npm dependencies, it is recommended to place those dependencies in the [non-root user](#non-root-user) directory. To achieve this, add the following line to your `Dockerfile`
@@ -37,6 +57,8 @@ ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
3757
ENV PATH=$PATH:/home/node/.npm-global/bin # optionally if you want to run npm global bin without specifying path
3858
```
3959

60+
This recommendation does not apply to npm itself, which is installed in `/usr/local/bin/npm`.
61+
4062
## Handling Kernel Signals
4163

4264
Node.js was not designed to run as PID 1 which leads to unexpected behaviour when running inside of Docker. For example, a Node.js process running as PID 1 will not respond to `SIGINT` (`CTRL-C`) and similar signals. As of Docker 1.13, you can use the `--init` flag to wrap your Node.js process with a [lightweight init system](https://github.com/krallin/tini) that properly handles running as PID 1.

0 commit comments

Comments
 (0)