Skip to content

Instantly share code, notes, and snippets.

@brianly
Forked from rain-1/docker node tip.txt
Created November 14, 2021 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianly/e5907ad453e9031da334d85cc0aec360 to your computer and use it in GitHub Desktop.
Save brianly/e5907ad453e9031da334d85cc0aec360 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment