Run Node.js in a Docker container


In this post, I explore how to run a Node.js web application in a Docker container based on the StrongLoop Process Manager image. I also have a requirement to export and deploy the Docker container to a server that lacks internet access.

docker-strongloop-pm.png

Create a new Node.js web app using express-example-app as the starting point

git clone https://github.com/strongloop/express-example-app.git

Head into the app folder and install dependencies

npm install

Start application using PM

slc start

Access http://localhost:3001 in a browser to ensure it works.

Shutdown PM

slc ctl shutdown

Create a new Docker container using StrongLoop PM image as the starting point

docker run --detach --restart=no --publish 8701:8701 --publish 3001:3001 --name strong-pm-container strongloop/strong-pm

Deploy example app by running following command in directory of app

slc deploy http://localhost:8701/ master

Access http://localhost:3001 in a browser to ensure it works.

Discover container’s id

docker ps -a

Commit container to a new image

docker commit 653811fd29f3 myimage

Save image to tar file

docker save -o myimage.tar myimage

Load image file in a new Docker instance (on another machine)

docker load -i myimage.tar

Run image in a new container

docker run --detach --restart=no --publish 3001:3001 --name strong-pm-container myimage

Access http://localhost:3001 in a browser to ensure it works.

Advertisements

Run Buildroot in a Docker Container


This post explores how you can run Buildroot in a Docker container. Follow the getting started to install Docker. I prefer using Docker with the PowerShell prompt on Windows 10.

docker-ubuntu-windows-10.PNG

To download and run the ubuntu image in a new container

docker run -it ubuntu bash

From another command prompt, run the following to find container id

docker ps -l

Use the -a option to see all containers

docker ps -a

Type exit to exit bash shell and stop container.

To return to container created earlier

docker start -ai container_id

Update apt-get package cache so that you can search and install additional packages

apt-get update

You should now be able to search

apt-cache search wget

And install your favorite tools

apt-get install wget

Obtain Buildroot

wget https://buildroot.org/downloads/buildroot-2016.11.2.tar.gz

Untar Buildroot

tar xvzf buildroot-2016.11.2.tar.gz

Install dependencies required to run Buildroot

apt-get install patch cpio python unzip rsync bc bzip2 ncurses-dev git make g++

Go ahead and build your Linux system.