Create a Node Microservice — Part 2

Sunny Kay
@sunkay IMHO
Published in
1 min readMar 21, 2016

Extending from part-1, this uses the Dockerfile to create an image of the microservice container.

Create Dockerfile

Dockerfile allows us to provide instructions for creating an image and run a container. Instead of using command line we can specify a Dockerfile to create our Node image..

File: DockerfileFROM ubuntu:latestRUN apt-get update
RUN apt-get nodejs nodejs-legacy npm

Save the above file and then build the image. Docker builds this image in layers and caches the layers.

host$> docker build -t nodejs:0.1 .

Now, lets copy our Microservice code in the container and build it again.

File: DockerfileFROM ubuntu:latestRUN apt-get updateCOPY hello-microsvc/package.json src/RUN apt-get nodejs nodejs-legacy npmCOPY hello-microsvc src/WORKINGDIR src/CMD ["npm", "start"]

Create a final version of the docker image

host$> docker build -t microsvc:0.2 .

Test your micro service by running the following command

host$> docker run -d -p 3000:3000 microsvc:0.2

Find the IP to use in the browser

host$> docker-machine ip
192.168.1.100

Go to http://192.168.1.100:3000/api/

--

--