How To Create Docker Image And Run Container

Posted By : Chandan Kumar Singh | 28-Feb-2018

Docker is a tool which is used for creating, deploy and run the application by using containers. The container is nothing but the package which consists all the libraries and dependencies required for running the application. By doing this, the developer can be assured that the application will run on any Linux system without any customized setting.

Let's start doing some stuff on Docker. We will install docker on Ubuntu, will create ubuntu image with Java-8 installed.

Install Docker CE on Ubuntu 14.04 LTS

$ sudo apt-get update

$ sudo apt-get install \
    linux-image-extra-$(uname -r) \

Update the package index.

sudo apt-get update

Install package to allow package from https

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \

Add Docker's GPG key.

curl -fsSL | sudo apt-key add -

setup stable repositry

 sudo add-apt-repository \
   "deb [arch=amd64] \
   $(lsb_release -cs) \

update the package index

sudo apt-get update

Install docker CE

sudo apt-get install docker-ce

Installation is done.

Now run the ubuntu image in docker by 

docker run -i -t ubuntu /bin/bash

Install Java in Image

apt-get update
apt-get install software-properties-common
add-apt-repository ppa:webupd8team/java
apt-get install oracle-java8-installer

commit the changes 

docker commit -a "authoername" -m "messg" CID(container id)

Now save the commited image

docker image save -o ubuntu-java8 ubuntu

here ubuntu is the image name which will be saved on disk by the name of ubuntu-java8.

To list the available docker image, run

docker images

to list the available docker containers, run

docker container ls -a

to run the docker image, run 

docker run -itd --name "myname" 21c6c6c37ece(image id) /bin/bash

to run the image container

docker exec  -it  2c536d59d66b(container id) /bin/bash


About Author

Author Image
Chandan Kumar Singh

Chandan is a bright Web Developer with expertise in Java and Spring framework and ORM tools Hibernate. He loves technologies like Blockchain and IoT.

Request for Proposal

Name is required

Comment is required

Sending message..