Hamsa K
8 min read | 3 years ago

How to Install Docker on Ubuntu 20 04

How to Install docker and  docker compose on ubuntu 20.04

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

Docker Compose is used for running multiple containers as a single service. Each of the containers run in isolation but can interact with each other when required. Docker Compose files are very easy to write in a scripting language called YAML. By using Docker Compose,users can activate all the services (containers) using a single command.

If you have an application that requires an Apache web server and Mysql database, you can create a Docker Compose file that can run both the containers as a service without the need to start each one separately.

This tutorial explains how to install docker and docker compose on ubuntu 20.04

Also Read -> How to Install Wine on Ubuntu 20 04

Step 1: Install packages

sudo apt update
sudo apt install curl apt-transport-https ca-certificates software-properties-common

Step 2: Install docker repository

we will import Gpg Key to your ubuntu system by running following command.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Also Read -> How to Install Apache Maven on Ubuntu 20 04

It displays output as 'OK'

then, add below docker repository

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \

Step 3: Install docker

Now update packages with apt and install docker

sudo apt-get update
sudo apt install docker-ce

once docker is installed, you can check service status with below command.

sudo systemctl status docker


● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-05-29 11:53:31 UTC; 30min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 9543 (dockerd)

To stop, start or restart Docker service, you can use following commands.

sudo systemctl stop docker
sudo systemctl start docker
sudo systemctl restart docker

you can check docker version with below command.

sudo docker version


Client: Docker Engine - Community
 Version:           20.10.6
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        370c289
 Built:             Fri Apr  9 22:47:17 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Server: Docker Engine - Community
  Version:          20.10.6
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8728dd2
  Built:            Fri Apr  9 22:45:28 2021
  OS/Arch:          linux/amd64
  Experimental:     false
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
  Version:          0.19.0
  GitCommit:        de40ad0

Step 4: Add local user to group

Add your local user to the docker group. so that you don’t need to use sudo when running Docker commands.

sudo usermod -a -G docker $USER

Now you can logout and login for the changes to take effect.you are able to run an image without using sudo.Next, run a hello world example to verify that everything is fine.

docker run hello-world


Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:5122f6204b6a3596e048758cabba3c46b1c937a46b5be6225b835d091b90e46c
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
For more examples and ideas, visit:

Also Read -> How to Install Apache Tomcat 9 on Ubuntu 20 04

Step 5: Install docker compose

you can install docker compose using apt with below command.

sudo apt install docker-compose

if you want latest version of docker compose, then you can install it using curl

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Also Read -> How to Install CouchDB on Ubuntu 20 04

you can replace version (1.29.2)available in the url above with latest version.

Now you can check docker compose version using following command.

docker-compose --version


docker-compose version 1.29.2, build 5becea4c

That's it. Now you have successfully installed docker on ubuntu 20.04

Also Read -> How to Install JAVA on Ubuntu 20 04

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy