|
19 | 19 | - [Install & Update Script](#install--update-script)
|
20 | 20 | - [Additional Notes](#additional-notes)
|
21 | 21 | - [Installing in Docker](#installing-in-docker)
|
| 22 | + - [Installing in Docker for CICD-Jobs](#installing-in-docker-for-cicd-jobs) |
22 | 23 | - [Troubleshooting on Linux](#troubleshooting-on-linux)
|
23 | 24 | - [Troubleshooting on macOS](#troubleshooting-on-macos)
|
24 | 25 | - [Ansible](#ansible)
|
@@ -154,6 +155,62 @@ RUN echo node > .nvmrc
|
154 | 155 | RUN nvm install
|
155 | 156 | ```
|
156 | 157 |
|
| 158 | +##### Installing in Docker for CICD-Jobs |
| 159 | + |
| 160 | +More robust, works in CI/CD-Jobs. Can be run in interactive and non-interactive containers. |
| 161 | +See https://github.com/nvm-sh/nvm/issues/3531. |
| 162 | + |
| 163 | +```Dockerfile |
| 164 | +FROM ubuntu:latest |
| 165 | +ARG NODE_VERSION=20 |
| 166 | + |
| 167 | +# install curl |
| 168 | +RUN apt update && apt install curl -y |
| 169 | + |
| 170 | +# install nvm |
| 171 | +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash |
| 172 | + |
| 173 | +# set env |
| 174 | +ENV NVM_DIR=/root/.nvm |
| 175 | + |
| 176 | +# install node |
| 177 | +RUN bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION" |
| 178 | + |
| 179 | +# set ENTRYPOINT for reloading nvm-environment |
| 180 | +ENTRYPOINT ["bash", "-c", "source $NVM_DIR/nvm.sh && exec \"$@\"", "--"] |
| 181 | + |
| 182 | +# set cmd to bash |
| 183 | +CMD ["/bin/bash"] |
| 184 | + |
| 185 | +``` |
| 186 | + |
| 187 | +This example defaults to installation of nodejs version 20.x.y. Optionally you can easily override the version with docker build args like: |
| 188 | +``` |
| 189 | +docker build -t nvmimage --build-arg NODE_VERSION=19 . |
| 190 | +``` |
| 191 | + |
| 192 | +After creation of the image you can start container interactively and run commands, for example: |
| 193 | +``` |
| 194 | +docker run --rm -it nvmimage |
| 195 | +
|
| 196 | +root@0a6b5a237c14:/# nvm -v |
| 197 | +0.40.1 |
| 198 | +
|
| 199 | +root@0a6b5a237c14:/# node -v |
| 200 | +v19.9.0 |
| 201 | +
|
| 202 | +root@0a6b5a237c14:/# npm -v |
| 203 | +9.6.3 |
| 204 | +``` |
| 205 | + |
| 206 | +Noninteractive example: |
| 207 | +``` |
| 208 | +user@host:/tmp/test $ docker run --rm -it nvmimage node -v |
| 209 | +v19.9.0 |
| 210 | +user@host:/tmp/test $ docker run --rm -it nvmimage npm -v |
| 211 | +9.6.3 |
| 212 | +``` |
| 213 | + |
157 | 214 | #### Troubleshooting on Linux
|
158 | 215 |
|
159 | 216 | On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
|
|
0 commit comments