Docker is an open source platform tool to automate the deployment of applications and its dependencies as a portable self-sufficient containers that can run virtually anywhere on any machine or OS.
Docker is a lightweight alternative to the virtualization provided by traditional hypervisors like VMs. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
Docker Features
Why to use docker ?
- Docker lets you ship application code faster, seamlessly in the form of containers and run anywhere in any environment like (dev,test,prod).
- As the docker containers are lightweight they are easily scalable.
When to use docker ?
- Docker containers can be used as a platform to build modern applications like microservices
- Docker is used to make the continuous integration process free from dependencies version conflicts
- It is used to make a complete package of any application into container that can be executed by novice or non-technical users
- It can be used if scalability is the concern as docker provides easy scalability
Docker Images and Containers
What is a Docker Image ?
Docker image is a read only template that defines the docker container. It has the code of application being built, its libraries and its dependencies.
What are Docker swarm, Kubernetes ?
These are the scaling and orchestration tools. Docker swarm – is the one provided by docker itself. Kubernetes – is another open source Container Management tool, which can manage scaling up the containers for eg: scaling upto 50-100 containers. It is compared with Docker swarm.
Docker Components
- Docker for Windows/Mac/Linux − This is the application needed to install in machines to run the docker containers.
- Docker Enginer − It is used to build docker images and create containers.
- Docker Hub − It is a cloud repository for various docker images, which later can be pulled by different users working in different envs. eg: pull jdk
- Docker Compose – It is a component used to multiple containers as a single service. By creating a docker-compose.yaml file and declaring all the required dependencies in it required for an application to run, eg: mysql db, jdk, to run a java based application.
Used to manage different containers and let them interact with each other. For eg: 2 services(deployed as 2 containers) also can interact with each other.
Docker Engine
Docker Engine is a client-server application which runs on your system having these components:
- A Server which is a daemon process which always running.
- A REST API which specifies interfaces which other programs or applications can use to instruct the daemon server what to do.
- A CLI which is the command line interface where you can directly via command talk to the daemon server and pass the instructions.

How to use Docker ?
After docker installation on your machine, do the following steps to build a docker image and run
- Check Docker version:
$docker -v - Build Docker file : and place Dockerfile in the current directory
$docker build -f Dockerfile -t docker-spring-boot .
where Dockerfile : from current dir
and target image file name : docker-spring-boot at current location with the dot - List Docker Images:
$docker images - Run Docker image at some port:
$docker run -p 8080:8080 docker-spring-boot - Optional : Before we can use the docker stack deploy command we’ll first run:
$docker swarm init
Sample Dockerfile example
FROM openjdk:8
ADD target/DockerTest-0.0.1-SNAPSHOT.jar DockerTest-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","DockerTest-0.0.1-SNAPSHOT.jar"]
Then build using Dockerfile
$ docker build -f /path/to/a/Dockerfile .
How to Make a Jenkins Pipeline :
Step 1: create various jobs for various services
Step 2: Link Git url for each job
Step 3: Add a build script which does:
>mvn clean install
>builds a docker image
>then push it to docker Hub (i.e a docker online repository)