Skip to content

Instantly share code, notes, and snippets.

@cthos
Last active September 25, 2015 23:59
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 cthos/4b3c8f1388392acb5334 to your computer and use it in GitHub Desktop.
Save cthos/4b3c8f1388392acb5334 to your computer and use it in GitHub Desktop.
Explaining what I mean about npm-script and Docker

Dockerfile

FROM node:0.12.7

RUN apt-get update -y
RUN apt-get install -y libcairo2-dev libjpeg62-turbo-dev libpango1.0-dev libgif-dev build-essential g++ software-properties-common

RUN mkdir /home/dockerthing

EXPOSE 4000

WORKDIR '/home/dockerthing'
ENTRYPOINT ["npm", "run"]

If you need to run things like npm install (you might), you can change the entrypoint here to just "npm" and pass -- run {foo} below.

Package.json

{
  "name"    : "dockerthing",
  "version" : "0.1.0",
  "main"    : "main.js",
  "scripts": {
    "docker" : "docker run -i -t -p 4000:4000 -v `pwd`:/home/dockerthing dockerthing/docker",
    "build-docker" : "docker build -t dockerthing/docker .",
    "test": "grunt test"
  },
  "dependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-jshint": "~0.10.0"
  }
}

Usage

$ npm run build-docker
$ npm run docker -- test

That last bit winds up running npm run test inside of the container which is the same folder as the Dockerfile since I'm mounting pwd to /home/dockerthing.

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