Pre-requisite to install Docker on Ubuntu
To install Docker, you need the 64-bit version of Ubuntu operating system.
- Ubuntu 20.04, 19.10 or 18.04
- Root user or sudo privileges
Installation of Docker on Ubuntu – Step by Step
Step #1
Uninstall old version of Docker, if any. For this tutorial, I will use Ubuntu 18.04 for reference. All instructions are the same. Therefore, applicable for Ubuntu 20.04 and other Ubuntu Flavours.

it’s OK, if apt-get command reports, “could not find package“. There is no old Docker package installed in my Ubuntu. The latest version of Docker engine is known as docker-ce.
Step #2
Select your preferred installation method out of these 3 listed. I will show you installation using all three methods one by one.
Download “Deb” package and install it manually. It may be useful, in case the internet is not available on some air-gapped systems.
Use the “automated convenience” script to install Docker.
Step #3
Set up the Repository and add Docker’s official GPG key using apt-get command. Let’s follow command one by one :-
Update apt package index.
$ sudo apt-get update

Allow apt command to use repository over HTTPS.
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common

Add official GPG key of Docker using curl command as shown in image. Then verify the entry of Docker key using the apt-key command.

$ sudo apt-key fingerprint

Step #4
Setup Repository for architecture X86_64/AMD 64-bit as shown in the image. It is applicable to most of the current systems.

Replace amd64 with armhf or arm64 architecture. Set it as per your system requirements. Example replace “deb [arch=amd64]
” with “deb [arch=arm64]
” or “deb [arch=armhf]
“.
Step #5
Install Docker-ce, Docker-cli and containerd packages from repository. This can be done by using apt-get command.
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io

Step #6 (optional)
If a specific version of docker needs to install. Select it from repository and feed version in apt-get command.
Firstly, List Docker-ce packages from repository
$ apt-cache madison docker-ce
Provide version string from the list, into the apt-get command.
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
Check your docker version.
$ sudo docker -v
Run your first docker container “Hello World”.
$ sudo docker run hello-world
Video – How to install Docker using the apt repository
Click on Download link and choose your Ubuntu distro from the list.
Now browse to directory “pool/stable“. Select your architecture (amd64, armhf, or arm64). Then download “.deb” packages as per your ubuntu distro.
For example, check out the download path for Ubuntu 18.04. Make sure you download all three packages Docker-ce, Docker-cli and containerd.

If your system doesn’t have internet due to security reasons. You can download it to alternate PC. Afterwards, transfer it to your’s using ssh or USB stick.
Use Curl command, if you want to download Docker packages using terminal.
$ sudo curl -O "path to download file"
For Example, I have downloaded it for Ubuntu 18.04
$ sudo curl -O https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/docker-ce_19.03.9~3-0~ubuntu-bionic_amd64.deb $ sudo curl -O https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/docker-ce-cli_19.03.9~3-0~ubuntu-bionic_amd64.deb $ sudo curl -O https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/containerd.io_1.2.6-3_amd64.deb

Keep in mind, you should install these packages in a defined sequence. First containerd, then docker-ce-cli and lastly docker-ce package.
If you will miss the sequence. As a result, you can encounter the package dependency error.
Run “dpkg” command with –i option to install your docker packages.
$ sudo dpkg -i /path-to-package.deb

Run Docker and verify docker engine is installed correctly with the “hello-world” image.
$ sudo docker run hello-world

if image is not available in local registry.”Docker run” pulls image from Docker hub by default.
Video – How to install Docker using Deb packages
If you love automation and want to deploy Docker. Above all, if you are a power user. Then docker convenience scripts are for you.
Install test or edge versions of Docker-community scripts. So, you can try them in a testing environment. However, Docker doesn’t recommend these for production. Obviously, for the following reasons –
Download script and audit before running it on local system.
Open terminal and run curl and sh command to download and run script.
$ curl -fsSL https://get.docker.com -o get-docker.sh

$ sudo sh get-docker.sh

Docker command doesn’t run in case of the non-root user by default. However, this article may help to run it as a non-root user.
Docker version should be updated manually. Rather, you re-run the script to upgrade. Because it’s not recommended by Docker.
Run Docker to Check, whether Docker-CE is working fine or not.
$ sudo docker run hello-world

Video – How to install Docker on Ubuntu using scripts
To remove docker container from Ubuntu, Run apt-get purge command
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
Delete all images, containers, volumes and customized configuration manually. Therefore, run “rm” command with precaution. Make sure you are deleting residue Docker files only.
$ sudo rm -rf /var/lib/docker
Use systemctl or service command to start docker manually. You can use service command if systemctl does not support on your distro.
$ sudo systemctl status docker

$ sudo systemctl stop docker

$ sudo systemctl start docker

$ sudo service docker start

There are 3 methods to connect or ssh to Docker container –
#1 Docker exec command
#2 Docker attach command
#3 using SSH command
#0
List Docker containers to find out, which container need to ssh or remotely connect
sudo docker ps

#1
To connect your local container, Run Docker exec command from the terminal. In this case, my container name is “bb“. Option “–it” instructs docker to allocate pseudo TTY and creating an interactive bash shell.
$ sudo docker exec --it "Container name" /bin/bash

#2 Connect to your running docker using docker attach command. So then, you can see all commands running in a container. Basically, it allows you to connect I/O and error stream of your running container. Also, it can help to take multiple sessions of a container.
sudo docker attach "Container Name"
For example, I am running Ubuntu docker container with name “topdemo“. In addition to, “top” command as a background process.

Docker attach command will show the output of “top” command. In this case, running in the container background. Press “Ctrl + c” to stop container. Additionally, you can start the container with sudo docker start “container-name” command.
Press Ctrl + p and Ctrl + q to detach from container.

#3
Using the ssh command, you can connect both local and remote containers. You just need to know the IP address or hostname of the running container.
How to find the IP address of Docker container
Run Docker inspect command to find out the IP address of the container. For instance, The IP address of alpine1 container is 172.17.0.3 and alpine2 shows 172.17.0.4.
sudo docker inspect -f "{{.NetworkSettings.IPAddress}}" Container-Name

Check connectivity using the ping command to a remote container. Option -c specifies the count of network packets. For example, I checked the connectivity of alpine2.
ping -c 5 "IP address of container"

Make your sure you have SSH installed in your system. Run “service ssh status” command to verify. Then connect your container using ssh.
ssh root@ip-of-container
You may get connection refused error, because your container may not Dockerize with ssh service.
Conclusion
I hope, Now you know Docker bit more. After, reading my post on “How to install Docker on Ubuntu and SSH to Docker container“. I will share Docker commands in next post, so stay tuned.
By the way which operating system is your favourite? Generally, to run “Docker containers“.
Please give your answer in the comment section.