|
| 1 | +# Node.js Docker images |
| 2 | +This image contains Node.js, yarn and a postgresql client and basic build |
| 3 | +tools. For yarn we use the 1.0 version distributed from their apt repository. |
| 4 | +Currently these tags are available: |
| 5 | + |
| 6 | +* Node.js 18: `18` |
| 7 | +* Node.js 20: `20`, `lts`, `latest` |
| 8 | + |
| 9 | +All versions contain node.js at the specified version, npm and yarn. They also |
| 10 | +include the postgresql client applications (e.g. psql and others) and include |
| 11 | +basic build tools allowing you to build C/C++ node.js extensions as well. |
| 12 | + |
| 13 | +## Extended images |
| 14 | +You can also use the extended images (with the postfix `-extended`). These |
| 15 | +variants include dependencies for running browsers such as for usage with |
| 16 | +puppeteer. |
| 17 | + |
| 18 | +## Full images |
| 19 | +A larger variant still is also available (with the postfix `-full`). These |
| 20 | +images include preinstalled firefox and chromium browsers, making them suitable |
| 21 | +for end-to-end testing. |
| 22 | + |
| 23 | +## Usage |
| 24 | +For basic usage instructions, also see our [debian image] detailed usage |
| 25 | +instructions. Basic usage when using docker compose is shown below: |
| 26 | + |
| 27 | +```yaml |
| 28 | +services: |
| 29 | + # ... |
| 30 | + app: |
| 31 | + image: ghcr.io/tweedegolf/node:lts |
| 32 | + user: "$USER_ID:$GROUP_ID" |
| 33 | + command: [npm, run, server] |
| 34 | + volumes: [".:/app"] |
| 35 | + working_dir: /app |
| 36 | + # ... |
| 37 | +``` |
| 38 | + |
| 39 | +## Extending for production |
| 40 | +When running this image in a production setting, you should set up a few things: |
| 41 | + |
| 42 | +* Create a user that your application will run under |
| 43 | +* Make sure that user will be the default user |
| 44 | +* Set the `ROOT_SWITCH_USER` environment variable to your user as well to |
| 45 | + prevent the application accidentally running as root |
| 46 | +* Copy the full appllication and its dependencies into the image |
| 47 | +* Set a command that will run the application |
| 48 | + |
| 49 | +See for example the Dockerfile below: |
| 50 | + |
| 51 | +```Dockerfile |
| 52 | +FROM ghcr.io/tweedegolf/node:lts |
| 53 | +RUN useradd -C Application -m -U app |
| 54 | +ENV ROOT_SWITCH_USER app |
| 55 | +ENV NODE_ENV production |
| 56 | +COPY --chown=app:app ./build /opt/application |
| 57 | +WORKDIR /opt/application |
| 58 | +CMD ["node", "index.js"] |
| 59 | +USER app |
| 60 | +``` |
| 61 | + |
| 62 | +[debian image]: https://github.com/tweedegolf/docker-debian-image |
0 commit comments