Create a docker container from a node app and run it, because we're hipster like that.
WIP don't use for serious apps yet!
I'd love to hear your feedback. There are a lot of details to flesh out yet. Also checkout my wish list below.
npm install node-container
Give it the path of your node app...it'll do the rest (ideally). Note: The docker daemon needs to run somewhere accessible.
You can do
npm test to see it in action.
The first time you run it can take a while, since it needs to fetch the base images.
Subsequent runs should be pretty fast.
var containerize =// pass it the directory of your node app, config is optional
container is the output of
docker inspect [container].
There you'll find the containers id, pid, network settings etc.
All of these are optional, but you probably want to at least set the docker config.
It can also be specified in the environment as
// docker confighost: ''port: 4243// socketPath: '',// prefix for images and containers, eg 'prefix-appname' or 'prefix/imagename'prefix: 'tests'// whether to run the container or notrun: true// whether to monitor the node process with mon or notmonitor: true
What does it do exactly?
npm packs your app, so you get all the npm goodies you expect
- Copies over our Dockerfile
- Build an image from our Dockerfile with your app in it. The image provides
- a stable, updated ubuntu 12.04 base system
- the latest stable node version
- the mon process monitor (
visionmedia/mon) to keep your app running
- and runs
npm install --productionfor your app
- Runs a container from the image
- which runs
npm startfor your app
- and monitors it with
What do I need to do?
- If your app listens to a port, it has to get it from
- If you want to listen to a specific port, you can specify it in your package.json with
port: 1234otherwhise it defaults to
3000. If you don't want to expose it to the world you can set
- Your app needs to be runnable with
Options you can set in your app's package.json
Take a look add the test app.
- use node version as specified in package.json
- persistent volume support
- be more flexible wrt docker run options etc
- evaluate if it's possible to run apps as non-root user
- find a better way to negotiate ports
If you find a bug, have a feature request or any kind of question, please open an issue or submit a pull request. I'm open for discussing any kind of idea for node-container.