Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

openwebcraft/nodejs-docker-starter

Repository files navigation

nodejs-docker-starter

A bare bones containerized (Docker) development environment for Node.js.

Overview

A simple hapi.js-based web application and a MongoDB make up a multi-container Docker application.

"Infrastructure as Code"

The setup is aimed at providing both, a local development enviroment and optimized developer experience as well as support for building deployment artifacts for a Continuous Integration and Continuos Deployment pipeline.

We`re using docker-compose to define and run a multi-container/ multi-service Docker applications:

  1. web Node.js hapi web application
  2. db MongoDB database

Assumption and Prerequisites

*nix environment, i.e. Linux or macOS.

Docker installed, check w/ docker --version.

docker-compose installed, check w/ docker-compose --version.

Usage

The multi-container environment is composed as follows:

  1. The individual services are configured in the file docker-compose-services.yml, looked down, bare-minimal configuration. For convenience the default docker-compose file name is used.

  2. For the development enviroment the services in 1. are extended in the file docker-compose.yml, basically adding additional development juice: mapping the local directory, adding nodemon w/ debug option, etc.

  3. For a 2nd enviroment, here integration the services in 1. are extended in the file docker-compose-integration.yml, using pre-build images.

Development Enviroment - docker-compose.yml

  • nodemon
  • NODE_ENV=development
  • Ports exposed to host:
    • Web: 8000
    • Node.js debug: 5858
    • MongoDB: 27017

Build the container for the web application, onetime... or if you make changes to the Dockerfile (e.g. installing system packages or global NPM modules):

docker-compose build

Start the development enviroment, w/ logs from all services on stdout.

docker-compose up

... to terminate: Ctrl+C.

Start the development enviroment as a daemon:

docker-compose up -d

... and point your browser to the url http://localhost:8000.

To tail the log files for the web application:

docker-compose logs -f web

To install a NPM module. e.g. hapi, into the RUNNING web container:

docker-compose exec web npm install hapi --save

To install a NPM module. e.g. mongodb, into the STOPPED web container:

docker-compose run web npm install mongodb --save

To stop the enviroment:

docker-compose stop

Integration Enviroment - docker-compose-integration.yml

  • pm2
  • NODE_ENV=production
  • Ports exposed to host:
    • Web: 80

Assuming there is a automated build from Git commits set up, similiar to Docker Hub's Automated Builds.

... or even manually:

cd app/web; \
  docker build -t matthiasg/nodejsdockerstarter-web:latest .; \
  docker push matthiasg/nodejsdockerstarter-web:latest

Start the integration enviroment, w/ logs from all services on stdout.

docker-compose -f docker-compose-integration.yml up

... to terminate: Ctrl+C.

Start the integration enviroment as a daemon:

docker-compose -f docker-compose-integration.yml up -d

... and point your browser to the url http://localhost.

To tail the log files for the web application:

docker-compose -f docker-compose-integration.yml logs -f web

About

A bare bones containerized (Docker) development environment for Node.js.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published