Docker is on the official Ubuntu repository, but that version is likely to be out of date. Instead, we will download Docker from Docker's own official repository.
First, let's install the packages that'll ensure apt can use the Docker repository over HTTPS:
$ sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
Then, add Docker's official GPG key. This allows you to verify that the Docker package you have downloaded has not been corrupted:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
The preceding command uses curl to download the GPG key and add it to apt. We can then use apt-key to verify that the key has the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88:
$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22
Then, add the Docker repository to the list of repositories for the apt search for when it's trying to find a package:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Finally, update the apt package index so that apt is aware of the packages in the Docker repository:
$ sudo apt update