Skip to content

Instantly share code, notes, and snippets.

@rain-1
Last active December 24, 2021 07:04
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rain-1/2f5551e34f32b1ef3cd58d01478a4916 to your computer and use it in GitHub Desktop.
Save rain-1/2f5551e34f32b1ef3cd58d01478a4916 to your computer and use it in GitHub Desktop.
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 https://github.com/glowing-bear/glowing-bear.git
$ 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
@evantbyrne
Copy link

There are official Node Docker images available which may be useful as well: https://hub.docker.com/_/node/

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