Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Easily build NodeJS projects inside a docker container
Here's a quick dockerfile:
----------------8<-------------[ cut here ]------------------
FROM debian:latest
RUN apt-get update && apt-get install -y nodejs npm
----------------8<-------------[ cut here ]------------------
save that as Dockerfile and do: docker build -t node-builder .
You can use this to build npm projects. For example:
$ git clone
$ docker run -i -v `pwd`:/pwd -t node-builder
# cd /pwd/glowing-bear
# npm install webpack
# npm run build
exit and copy your build products out of the directory and you are done.
The best part is that I don't even have npm installed on my host at all.
None of the viruses in npm are able to run on my host when I do things this way.
Update: In fact we do not even need to make a dockerfile! Thanks to cepheus.
docker run -v `pwd`:/pwd -it node:16-buster-slim /bin/bash

This comment has been minimized.

Copy link

@evantbyrne evantbyrne commented Nov 13, 2021

There are official Node Docker images available which may be useful as well:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment