Docker is an open-source containerization platform that allows you to quickly build, test, and deploy applications as portable containers that can run anywhere
Docker is available for installation from the standard Ubuntu 20.04 repositories, but it may not always be the latest version. This tutorial covers how to install the latest version of Docker on an Ubuntu 20.04 LTS machine from the official Docker’s repositories.
1./ Installing Docker on Ubuntu
01- First, update the packages index and install the dependencies necessary as below:
$ sudo apt update $ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
02- Let’s import the Docker repository’s GPG key using the following
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
03- Once you done, add the Docker APT repository to your system:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
04- Now that the Docker repository is enabled, run the below commands to install the latest version of Docker, .
$ sudo apt update $ sudo apt install docker-ce docker-ce-cli containerd.io
=<VERSION> after the package name like below:
sudo apt install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io
05- Once the installation is completed, use the below command to enable the Docker service to start at system boot:
$ sudo systemctl enable --now docker
06- When a new version of Docker is released, you can update the packages using the standard
sudo apt update && sudo apt upgrade procedure. But, If you want to prevent the Docker package from being updated, use the below command:
$ sudo apt-mark hold docker-ce
2./ Verifying the Installation and Using Docker
By default, only
root and user with
sudo privileges can execute Docker commands. However, to execute Docker commands as non-root user you’ll need to add your user to the docker group. So, to do that, type in:
$ sudo usermod -aG docker $USER
02- Finally, to verify that Docker has been successfully installed and that you can execute the docker commands. we’ll run a test container that will print a Hello from Docker message, and exit:
$ docker run hello-world
docker : Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
3./ Uninstalling Docker on Ubuntu
01- Before uninstalling Docker, run the following commands to stop all running containers and remove all docker objects:
$ docker container stop $(docker container ls -aq) $ docker system prune -a --volumes
02- You can now uninstall Docker as any other package installed with
$ sudo apt purge docker-ce $ sudo apt autoremove
You have successfully installed Docker CE on your Ubuntu 20.04 LTS server. To learn more about Docker, check out the official Docker documentation.
What’s Next? You might want to check the following guides: