Install Docker on Ubuntu 18.04 | 20.04

Install Docker on Ubuntu

This post shows users and new students that how to Install Docker on Ubuntu 18.04 | 20.04. If your are going to Install Docker on Ubuntu then this post is ideal for you.

Docker is an open source software that use visualization at the operating system level. it is makes easy to create containers and container-based applications.

Docker makes easy task for developers for develop and deploy applications inside virtual containerized environments. Means container-based application run and work the same, doesn’t matter that where they are run and what platform they are running on.

Please Follow the below steps for installing Docker and Docker Compose on Ubuntu :

Step 1: Add Docker Official Repository

Run the below commands to install Required packages.

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

Next, Run the below commands to install Docker’s official GPG key. It is used to make sure that the packages installed from Docker’s repository are trusted.

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

Above command show an output like below:

Output:
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

Run the below commands to add it’s stable repository to Ubuntu.

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

With the above, Docker’s official GPG and repository is installed on Ubuntu.

If you have an older versions of Docker, then run the below commands to remove older versions.

sudo apt-get remove docker docker-engine docker.io containerd runc

If you wish to install specific version of Docker, then run the apt-cache command and then select the version that you want to install.

apt-cache madison docker-ce

Output:
docker-ce | 5:18.09.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:18.09.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
....

Choose the specific version from above list and, run the below commands with the version you want to install.

sudo apt-get install docker-ce=5:18.09.5~3-0~ubuntu-bionic docker-ce-cli=5:18.09.5~3-0~ubuntu-bionic containerd.io

If want to install just latest version, run the below commands.

sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Run the below commands for check, Docker is installed correctly:

sudo docker run hello-world

The above command give a result similar like below lines:

Output:
Hello from Docker!
This message shows that your installation appears to be working correctly.

Step 2: Install Docker Compose 1.27.4

Run the below commands below to download latest version of Docker Compose. At this time 1.27.4 the current version of Docker Compose.

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

For install a different version just replace 1.27.4  with the version you want to download.

Now,  run the below commands to apply executable permissions for binary file and create a link to /usr/binary

sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

For the test, run the below commands:

docker-compose --version

The above command give a result similar like below lines:

Output:
docker-compose version 1.27.4, build 0aa59064

That’s all!

Add your user account to Docker’s group to run Docker as a non-root user, for do that run the below commands:

sudo usermod -aG docker $USER

Now log out and login again.

That’s all

If you find any error and issue in above steps , please use comment box below to report.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top