Docker Installation on Ubuntu

Rakesh Jain
2 min readJun 3, 2020

OS: Ubuntu Bionic 18.04 (LTS)

Uninstall old versions

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

Install using the repository

SET UP THE REPOSITORY

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

$ sudo apt-get update$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
$ sudo apt-key fingerprint 0EBFCD88
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]

Use the following command to set up the stable repository.

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

INSTALL DOCKER ENGINE
Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

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

Install a specific version using the version string from the second column, for example, 5:18.09.1~3–0~ubuntu-xenial.

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
Verify that Docker Engine is installed correctly by running the hello-world image.
$ sudo docker run hello-world

Uninstall Docker Engine

Uninstall the Docker Engine, CLI, and Containerd packages:

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io

Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

$ sudo rm -rf /var/lib/docker
You must delete any edited configuration files manually.

Enable Bash Completion -

#apt-get install bash-completion#curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh

Source bash_completion file in bashrc file.

#cat .bashrc
source /usr/share/bash-completion/bash_completion

Hope you like the tutorial. Please let me know your feedback in the response section.

Happy learning!

--

--