Spring Boot with Docker

Docker is a tool which is used to automate the deployment of applications in lightweight containers so that applications can work efficiently in different environments.

Common Docker Terms

Docker Container

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

Docker Image

A Docker image is a collection of files that bundle together all the essentials, such as installations, application code and dependencies, required to configure a fully operational container environment.

Docker File

A Dockerfile is a script/text configuration file that contains collections of commands and instructions that will be automatically executed in sequence in the docker environment for building a new docker image.This file is written in a popular, human-readable Markup Language called YAML.

Docker Hub

Docker Hub is a service provided by Docker for finding and sharing container images with your team. 



Step by step process

Install docker engine

Follow docker official site for installation

Create docker file

Create plain text file in root of the project and named it as Dockerfile
Write this content in the file Dockerfile:


Create project build

Before creating a docker image make sure you have created project build.
If you already created the latest build then you can skip this step.

Create docker image

Use this command for creating docker image:
$ docker build -t username/repository:tag 

– aurigait is the username of your docker hub account
– springDocker is the name of the repository in docker hub (if repository does not exist in docker hub it will automatically created when you push image to docker hub)
– new-release is the tag which is used to differentiate multiple image in same repository

Pushing image to docker hub

  1. Login with docker hub credential 
    $ docker login -u username
  2. For pushing image use this command:
    $ docker push username/repository:tag

Till this step you have created a docker image which can run on any machine having docker installed.


Running docker image

Before running the image please make sure you have docker installed on your machine.
Use this command:
$ docker run -p [host port]:[container port] username/repository:tag



Docker Compose

Docker Compose is used to run multiple containers as a single service. You could create one file which would start multiple containers as a service without the need to start each one separately.


Step by step guide:


1. Install docker compose

Refer official docker document: https://docs.docker.com/compose/install/

2. Create docker-compose.yml file

A docker-compose.yml is a config file for docker-compose.


4. Running docker container

For running docker container you need to use following command which will follow the step by step process in docker-compose.yml file and run the container.

4. Stopping docker container

For stopping docker container you can follow this command: