Day 11: Using Docker to build and deploy a distributed app


Docker allows users to package an application with all of its dependencies into a standardized unit for easily deploying on cloud for use in a distributed manner. It allows developers to build, ship and run applications on any platform with ultra high efficiency across thousands of machines. This has been highly adopted by the dev community to collaborate around libraries of containers.

As shown in the Google search trends graph below, Docker’s rise has been exponential with several billion containers being run every week.

Google Search Trend for ‘Docker’

We all have been through the painful process of setting up local dev environments and sharing application configurations at some point or another. Now Docker does sound awesome to get over all that headache, so I thought will give it a spin. Lets get started.

Project: Setup Docker and create a simple webapp container which will be hosted in a public container repo in Build and deploy the webapp to Docker and pull it from the cloud running it on a Ngnix Webserver locally.

All the code for this project can be found on my github

Docker container used in this project can be found on my registry

Step 1: Install Docker

Follow the instruction for installing Docker as per your OS: Mac, Linux and Windows.

Step 2: Run Docker

  • Open the installed Docker Terminal from your Apps which shows the most popular laptop sticker you would see of the whale!
  • Test your installation by running, which would
docker run hello-world
  • Verify if you have python and java already installed, if not go ahead and install it.
  • Try pulling out a container image from docker repo.
  • Now that the image is pulled you can run any command on it.
  • To check the list of images that you have pulled use the following cmd.
  • Finally to check the containers that are running or were run use this.

Step 3: Creating and using Docker containers for Webapp

Now that we have gotten familiar with basic Docker command, lets get started and build a Docker image of our own and use it to run a webapp on Ngnix Webserver.

For the purpose of this project the image that we are going to use is a single static page that I have created and posted to my github page. I have hosted this as a public repo container in Docker registry — harini/static-site.

  • You can now download and run the image directly in one go using docker run as follows. This will output that Ngnix is running..
docker run harini/static-site
  • However to run it as a webservice and open it in browser, run the following commands to get the IP and port numbers. Optionally you can also run it on a specific port as shown in the last command.
  • Now you can open the IP and port in a browser to see the static page served on the Ngnix webserver.

More on creating your own docker container image next time!

Day 11 of #100DaysOfCode DONE

If you enjoyed this, please click 👏 so that others can enjoy it as well. Follow me on Twitter @HariniLabs to get the latest updates or just to say Hi :)

PS: I curate a bi-weekly #WomenInTech newsletter for a dose of inspiration from the world of tech and yes men can signup too! Get it here :)