Docker Kickstarter

By: Kannan Ramamoorthy On: Sun 16 July 2017
In: Docker
Tags: #Architecture #Computing #Virtualization #Docker

Docker is one of the buzzword, that we encounter commonly nowadays. Tried it out and realized a lot of advantage for myself. This article is intended to give a comfort start for anyone who starts with docker.

This article doesn’t dive deep into the architecture of the Docker. But, helps you get a high-level idea and get started. Also, I tried to explain the docker jargons that you encounter commonly, so that you can skim through any other setup articles that you encounter.

Before getting started,

If you are already a bit familiar about Docker, but need a kickstart, this article is primarily for you.

If you are already aware of the concept of Virtual Machines, Docker is a similar technology, but efficient and light weight because of its design.

If you are never heard about such terms, Docker helps you to run (virtual) machines with different OS inside you *nix/Mac/Windows machines. Imagine if you are able to run a Centos, Ubuntu, and Fedora inside your machine as if you are running it on different machines. The major difference is you will be able to access it using only terminal. Read through OS Virtualization and Docker, before reading further.

Advantages:

  • You can have Dev/QA/Staging environments, that exactly mimics your production environment. So that you can avoid inconsistencies and issue that are not reproducible.

  • You can have the environment that is getting built from a plain text file (Dockerfile), so that just sharing that file helps you to share the environment setup and get it created in minutes.

  • Since the complete environment setup can happen from a plain text file, the environment can be easily reviewed and understood by anyone.

  • Since Docker is available for all the OS (have to mention that Windows docker is not so good), easy to have the environments up and running, so that you can focus on your task, rather than spending time in environment setup.

  • Can even be used in production along with additional support such as Openshift, preferable for Microservice architecture.

  • Sandboxed environments. Since docker provides a level of abstraction, you have multiple components in a single server, running side-by-side, without changing the conflicting parameters such as ports.

  • Relatively very cheap in terms of memory and CPU when compared to other VM technologies. Hence you can create as many as you want and throw it away, without polluting your local machine. In my Mac, I have a bunch of Linux flavored docker containers (we will see what it means) for various applications without affecting the my usability.

Kickstart:

We install Docker in our host.

A host is a machine on which you install the docker. This helps you to create as many Docker containers as you want.

Docker image is the template of the environment that you wish to have. It can be any plain linux distro, or a customized one with additional applications such as Oracle DB or Tomcat. There are lot of images already available in the Docker hub(default registry).

Docker registry is the hub containing Docker images which we can make use of.

You pull an image from Docker registery.

You run a Docker Image to create a Docker container. You can only directly use a Docker container as if your are using a machine. You can create many independent containers from the same image.

Once a container is created you can start or stop it, the same way you switch on/off a machine.

If default image is not enough, you can write a Dockerfile that contains additional customization required for you, on top of existing images.

Dockerfile is a simple text file containing the docker commands that do the additional customization required for your container(via image). You build a Dockerfile that creates a image in your local, with the customization and you can run the containers from the image and use it. It is mandatory that the file name has to be Dockerfile.

Apart from the above basics, you can facilitate multi-container app using Docker Compose , you can map ports from container to host, and you can do lot more with Docker.

Example – Having Tomcat server up and running:

  • Once you installed docker on your machine, you can pull the image with the below command,

docker pull tomcat
  • Once the above command is completed you will have a tomcat image in your machine, which you can check with the command,

docker image ls
  • Now that you have an image of a tomcat docker you can run and use it. The below command runs image in detached mode (-d), so that your terminal is not interrupted, with the 8888 port of your local maps to the 8080 port of the tomcat image.

docker run -d -p 8888:8080 --name tomcat_container tomcat

Now when you hit http://localhost:8888 , you will see tomcat available there.

  • Just similar to you ssh to a remote machine, on a running container you can enter and browse through it using the below command. With this you ask docker to execute (exec) bash in interactive terminal(-it) for the container with given name.

docker exec -it tomcat_container bash

Reference:

Strongly recommend this tutorial for a deep dive into Docker and Kubernetes.


If you found the article helpful, please share or cite the article, and spread the word:


For any feedback or corrections, please write in to: kannangce@rediffmail.com

comments powered by Disqus