Public Repository

Last pushed: 2 years ago
Short Description
A base container for building nodejs app containers.
Full Description

Find the source on bibucket

This is a container based off the official node build for easing the process of automating builds of nodejs applications.

It is a base container and does nothing by itself. The intention is for this container to be easily extended to containerize node applications.

What it does

  • Exposes ports 80 and 443
  • Expects source of node application to be copied to /var/opt/nodesrc
  • Runs an ENTRYPOINT script to install via npm and bower ( if necessary ) on first run of container.
  • Provides an overrideable NODE_ENV envrionment variable of woosteln_nodebase
  • Runs the app from the /var/opt/nodesrc directory using CMD [node, index.js]

How to extend it

Basically you want to create a Dockerfile within your node apps directory extending this image, copy your sourcecode into /var/opt/nodesrc and make sure it's configured ( either by using the NODE_ENV environment variable or a hardcoded configuration file ) to listen on ports 80 or 443. ( I would recommend using node-config )

Example Dockerfile:

FROM woosteln/nodebase:latest
ADD . /var/opt/nodesrc

You can then run:

docker build -t my/exampleNodeContainer .
docker run -d --name myExample -p 8080:80 my/exampleNodeContainer

And it should be good.

Getting advanced

If you make your extension and then create an automated build process based on your project's repository, boom. You have an automatically containerized nodejs application.

Maybe you override the CMD to be CMD [ 'npm', 'test' ] so you use it in CI. Or maybe (keep it portable ) your CI script executes

# Pull latest
docker pull my/exampleNodeContainer
# Stop and remove existing
docker stop myExample
docker rm myExample
# Run tests
docker run --rm --name myExample -p 8080:80 my/exampleNodeContainer npm test



Regarding your npm packages.... You might want to freeze them to a particular version. We're just going to run npm install on whatever you've declared.

Regarding bower... same things goes. If you've provided a bower.json in your app, make sure the package versions are exactly the ones you want. We run bower without any prompts so if there are version conflicts, the install will fail!

Docker Pull Command