Docker – Basics and setup on Ubuntu

What is DOCKER?

  • Is a Lightweight, Open, Secure platform
  • It simplifies building, shipping and running applicatons in different environments.
  • Enables you to separate your applications from your infrastructure so you can deliver software quickly.
  • Docker runs natively on Linux and Windows servers. (windows 2016 server)
  • Docker relies on Images and Containers.

For development, if you have a windows/Mac machine, you have to have a virtual machine. If you are developing on Linux  eg Ubuntu, docker can run natively.

Images and Containers

An image is something that is used to build a container.


An image is a readonly template that is composed of layered filesystems. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry (such as, because they can become quite large, images are designed to be composed of layers of other images, allowing a miminal amount of data to be sent when transferring images over the network.

Containers are created from an image that can be started, stopped , moved and deleted. You can have many running containers of the same image.

Docker vs Virtual machines

Containers and virtual machines have similar resource isolation and allocation benefits — but a different architectural approach allows containers to be more portable and efficient.


Virtual machines include the application, the necessary binaries and libraries, and an entire guest operating system — all of which can amount to tens of GBs. Depending upon the hardware and other things it can be a bit expensive yo start up a virtual machine. They run well but they are big.

Containers include the application and all of its dependencies –but share the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud.

Why should I use docker?

  • Docker can setup the environment very quickly : Our app may have a DB, server,  supported software version like java versions,etc   etc. Setting up these in every machine could be challenging. We should maintain that everyone uses the same version of the software etc. Also sometimes you need to debug production code, and for that you need to run it locally. With Docker, you simply take copies of your live environment and run them on any new endpoint running a Docker engine.
  • Eliminates enviornment conflicts : Packaging an application in a container with its configs and dependencies guarantees that the application will always work as designed in any environment: locally, on another machine, in test or production.
  • Ship software faster and at scale : Docker allows you to dynamically change your application — from adding new capabilities and scaling services, to quickly changing problem areas.

Lets start by installing it first. I am using ubuntu rightnow. So docker will run natively on my machine. For windows the installation is pretty easy too. It just requires a virtual box which will be done by the wizard. I will try to write anoter post for windows installation. Once the installation is done the docker commands are going to be same for any setup.

Ubuntu Setup steps:

Docker requires a 64-bit installation regardless of your Ubuntu version. Additionally, your kernel must be 3.10 at minimum. To check use the following command in terminal:

dj@Dj:~$ uname -r

-> Update package information, ensure that APT works with the https method, and that CA certificates are installed.

$ sudo apt-get update

$ sudo apt-get install apt-transport-https ca-certificates

-> Add the GPG key for the official Docker repository to the system:

$ sudo apt-key adv --keyserver hkp:// --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

-> Find the entry for your Ubuntu operating system. The entry determines where APT will search for packages. I am using ubuntu 16.04 for which full name is Xenial 16.04 (LTS). Other versions could be Trusty 14.04 (LTS), Precise 12.04 (LTS) etc.

$ sudo apt-add-repository 'deb ubuntu-xenial main'

-> Update the package database with the Docker packages from the newly added repo:

$ sudo apt-get update

-> Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:

$ apt-cache policy docker-engine

You should see output similar to the follow:

Installed: (none)
Candidate: 1.11.1-0~xenial
Version table:
1.11.1-0~xenial 500
500 ubuntu-xenial/main amd64 Packages
1.11.0-0~xenial 500
500 ubuntu-xenial/main amd64 Packages

Notice that docker-engine is not installed, but the candidate for installation is from the Docker repository for Ubuntu 16.04. The docker-engine version number might be different.

-> Install Docker:

$ sudo apt-get install -y docker-engine

Lets test using ‘docker ps’ which will list all containers.


If you are getting above error you need to add your current user [suppose you’re logged in as ubuntu] to docker group as follow

$ sudo usermod -aG docker ubuntu

then logout & login again into the system or restart the system. Test again


Verify docker is installed correctly.

$ docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints an informational message. Then, it exits.


To check what all images we use – docker images
To check all instance use – docker ps -a


Since the container is stopped so its showing stop

To remove a container – docker rm

To remove an image – docker rmi


Thats it. Next we will do some other cocepts and windows setup.

%d bloggers like this: