# Remove old Docker installations to make fresh install.
$ sudo apt remove docker docker-engine docker.io containerd runc
# Check if update available for system packages.
$ sudo apt update
# Install required system packages.
$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# Add Docker's official GPG key to package manager.
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
# Add Docker repository to package manager source list.
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Install Docker packages from repository.
$ sudo apt install docker-ce docker-ce-cli containerd.io
# Check Docker version.
$ sudo docker --version
# Enable Docker service at boot.
$ sudo systemctl enable docker.service