How to Setup Docker step by step on Ubuntu machine

I am sure most of you have installed lots of application on single Virtual machine and faced challenges while maintaining them and facing memory or system issues and things become more ugly when you troubleshoot each application to fix the problem.

What should one do ? Cannot we isolate our apps so that we can easily find the problem ? Cant one app which is not working should be down and others should run as it is ? Yes, that correct that’s very much possible with docker and containers. They provide you isolated environment and are your friend for deploying many applications with each taking its own container.

In this tutorial, you’ll install and use Docker on Ubuntu 18.04. You’ll then work with containers , images and push an image to a Docker Repository. So lets get started.

Table of Content

  1. What is Docker ?
  2. Prerequisites
  3. How to Install Docker on ubuntu machine
  4. How to run Docker commands using Non Root user
  5. Working with docker images and containers
  6. Pushing docker images to docker hub
  7. Conclusion

What is Docker ?

🐟Docker is an open source tool for developing , shipping and running applications. It has ability to run applications in loosely isolated environment using containers. Docker is an application which helps in management of containers in a very smooth and effective way. In containers you can isolate your applications. Docker is quite similar to virtual machine but it is light weighted and can be ported easily.

Containers are light weighted as they are independent of hypervisors load and configuration. They directly connect with machines ie. hosts kernel.


  • Ubuntu machine preferably 18.04 version + , if you don’t have any machine you can create a ec2 instance on AWS account
  • Recommended to have 4GB RAM
  • At least 5GB of drive space
  • An account on Docker Hub if you wish to create your own images and push them to Docker Hub.

You may incur a small charge for creating an EC2 instance on Amazon Managed Web Service.

How to Install Docker on Ubuntu 18.04 LTS

sudo apt update
  •  Install some required packages for apt so that it can use over https
sudo apt install apt-transport-https ca-certificates curl software-properties-common
  • Add the GPG key for the official Docker repository to your system
curl -fsSL | sudo apt-key --keyring /etc/apt/trusted.gpg.d/docker.gpg add -
  • Add the Docker repository to APT sources
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
sudo apt update
  • Now, Install docker
sudo apt-get update && sudo apt-get install -y \ \
  docker-ce=5:19.03.11~3-0~ubuntu-$(lsb_release -cs) \
  docker-ce-cli=5:19.03.11~3-0~ubuntu-$(lsb_release -cs)
  • Docker should be started now, verify the status and version of docker.
  • Check the docker version
  • Docker is successfully installed and now you are reading to work with docker and containers.

How to run Docker commands using Non Root user

To enable users other than root and users with sudo access to be able to run Docker commands:

  1. Create the docker group
groupadd docker
  1. Add the users that should have Docker access to the docker group
sudo usermod -a -G docker jenkins   # To add Jenkins user to docker group
sudo usermod -a -G docker user1     # To add user1 to docker group
  1. Restart the docker service by following command
# The UNIX socket /var/run/docker.sock is now writable by members of the docker group.

service docker restart 

Working with docker images and containers

Most important part in docker is docker images which contains your code , environment to run it and several parameters. Docker images are stored on docker repository known as docker hub , though you can store it on your local machine as well.

  • To pull docker image ubuntu on your system
docker pull ubuntu
  • Now check the downloaded image.
docker images
  • In this tutorial we are providing the demo so we will use the same pulled docker image and run our first container , but you can update the same image with more configurations or as per requirements as well.
  • Run the first container
docker run -it ubuntu                # Here i and t provides you interactive shell access and ubuntu is image name
  • We used exit to come out of shell , so container has been exited. To check the containers details.
 docker ps -a

Pushing docker images to docker hub

  • Firstly you will need to login to docker hub with your credentials and then login.
docker login -u docker-registry-user
  • Before you push your docker image to docker hub , its highly recommended to to tag your image with your docker hub username .
docker tag ubuntu:latest  <dockerhub-username>/ubuntu:latest
  • After successful login in docker hub now push your docker image
docker push <dockerhub-username>/ubuntu:latest


In this tutorial you installed Docker, worked with images and containers, and pushed a image to Docker Hub

Hope this tutorial will help you in understanding and setting up Docker on ubuntu machine. Please share with your friends.

One thought on “How to Setup Docker step by step on Ubuntu machine

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s