How-to-Install-Docker-on-ubuntu-and-SSH-to-Docker-Container

How to install Docker on Ubuntu and SSH to Docker container securely – {2021 update}

In this “How to install Docker on Ubuntu and SSH to Docker container” tutorial, we will deep dive further with installation options and connectivity of Docker. It’s going to be an interesting Docker’s journey with these topics. –

  • How to install Docker on Ubuntu – 3 Methods
  • How to start Docker daemon in Ubuntu
  • Process of SSH/connection to Docker container -3 Ways
  • Uninstall Docker container
Check my post to know “What is Docker and How to install Docker on Windows

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.

If there is any old version of Docker installed like docker, docker-engine or docker-io. Just get rid of these with apt or apt-get remove command

Remove-any-existing-docker-from-ubuntu

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.

Setup the Docker repository and install Docker. It is the best and recommended approach for docker installation followed by many users.

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.

Method #1 Install Docker using the repository

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
update-package-index-to-install-docker

Allow apt command to use repository over HTTPS.

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

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.

Add-official-GPG-key-of-Docker
$ sudo apt-key fingerprint
apt key docker fingerprint validation

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.

add-stable-docker-repository

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
how-to-install-docker-on-ubuntu-using-apt-get

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

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.