Scripting with NodeJs and Docker

This is an example cli application that use NodeJs to build a command line binary and then use Docker to distribute and use it as container.

The code is hosted in bitbucket

This is using the NodeJs commander package in order to parse and use command line attributes and options.

#Cloning from source

First clone the repo

$ git clone git@bitbucket.org:alexsapran/nodejs-docker-cli.git

Lets first check that the application is working

$ make container 

This will take some time until it finish as it will download (if not already) the base image FROM node:7.0.0-onbuild.

Then when finish just run it as

$ docker run -it --rm alexsapran/example-cli 
Application started

  Usage: example-cli <options>

  Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -e, --example [e]  Print back whatever was in the input
$ docker run -it --rm alexsapran/example-cli -e This is a demo
Application started
Got input alex
Execution finished

Get pre-builded distributable container

You can directly use the last docker run command as it will automatically pull from dockerhub the latest version but you cannot alter it.

$ docker pull alexsapran/example-cli 
$ docker run -it --rm alexsapran/example-cli 
Application started

  Usage: example-cli <options>

  Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -e, --example [e]  Print back whatever was in the input

Build your own

Now you can use the commander to setup your solution based on NodeJs and docker and start your own project.

Alexandros Sapranidis

Software engineer, keen on wearing many hat, current Senior Software Engineer @Elastic cloud

Athens, Greece http://sapranidis.gr