Setting up Docker in Ubuntu
Note: The following steps are for installing Docker from the Docker repository instead of the default Ubuntu repository.
1. Uninstall any old versions of Docker:
sudo apt-get remove docker docker-engine docker.io
2. Update the software repositories:
sudo apt-get update
3. Install a few necessary packages that allow apt
to access repositories over HTTPS:
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
The purpose of these packages are:
- apt-transport-https: Allows APT package manager to access repositories over HTTPS
- ca-certificates: Allows the web browser and system to check security certificates
- curl: A tool for transferring data
- gnupg-agent: An agent that manages private keys
- software-properties-common: Adds scripts for managing software
4. Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
An OK
response is expected.
5. Add Docker’s repository to APT sources:
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
6. Update the package database:
sudo apt-get update
7. Verify the version of the package docker-ce
:
apt-cache policy docker-ce
A correct output will be as follow. Do note that the version number may differ.
8. Install the latest version of Docker:
sudo apt-get install docker-ce
Note: To install other version, use this command instead: sudo apt-get install docker-ce=<VERSION_STRING>
, where an example of <VERSION_STRING>
is 5:19.03.12~3–0~ubuntu-bionic
.
9. Verify that Docker is running successfully:
sudo docker run hello-world
You will expect to see the following: