This article was first published in: https://www.itcoder.tech/posts/how-to-install-and-use-docker-on-ubuntu-20-04/
Docker is an open source containerized platform that allows you to build, test, and deploy applications as portable containers. These containers can run anywhere. A container represents the operating environment of an application and contains all the dependent software needed for the software to run.
Docker is part of modern software development, continuous integration, and continuous delivery.
This tutorial will cover how to install Docker on Ubuntu.
Docker is available in the standard Ubuntu 20.04 software source, but it may not be the latest version. We will install the latest Docker package from Docker's official software source.
Installing Docker on Ubuntu is very straightforward. We will enable the Docker software source, import the GPG key, and install the package.
First, update the package index and install the necessary dependent software to add a new HTTPS software source:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Use the following curl
to import the GPG key of the source repository:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the Docker APT software source to your system:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Now that the Docker software source is enabled, you can install any available Docker version in the software source.
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo apt update
apt list -a docker-ce
The available Docker version will be shown in the second column. At the time of writing this article, there is only one Docker version (5:19.03.9~3-0~ubuntu-focal
) available in the official Docker software source:
docker-ce/focal 5:19.03.9~3-0~ubuntu-focal amd64
By adding the version = after the package name<VERSION>
To install the specified version:
sudo apt install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io
Once the installation is complete, the Docker service will start automatically. You can enter the following command to verify it:
sudo systemctl status docker
The output will be similar to the following:
● docker.service - Docker Application Container Engine
Loaded:loaded(/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active:active(running) since Thu 2020-05-2114:47:34 UTC; 42s ago
...
When a new Docker is released, you can use the standard sudo apt update && sudo apt upgrade
process to upgrade the Docker package.
If you want to prevent Docker from automatically updating, lock its version:
sudo apt-mark hold docker-ce
By default, only root or users with sudo privileges can execute Docker commands.
To execute Docker commands as a non-root user, you need to add your user to the Docker user group, which is created during the Docker CE package installation process. To do this, type:
sudo usermod -aG docker $USER
$USER
is an environment variable, representing the current user name.
Log out and log in again to refresh the user group membership information.
To verify whether Docker has been successfully installed, you can execute the docker
command. There is no need to add `sudo before, we will run a test container:
docker container run hello-world
If there is no such image locally, this command will download the test image, run it in the container, print out "Hello from Docker", and exit.
The output should look like this:
This container will stop running after printing the message because it does not have any long-running processes.
By default, Docker pulls images from Docker Hub. It is a cloud service mainly used to store Docker images in public and private sources.
Before uninstalling Docker, you'd better remove all containers, images, volumes, and networks.
Run the following command to stop all running containers and remove all docker objects:
docker container stop $(docker container ls -aq)
docker system prune -a --volumes
Now you can use apt
to uninstall Docker like other packages:
sudo apt purge docker-ce
sudo apt autoremove
We have shown you how to install Docker on an Ubuntu 20.04 machine.
To learn more about Docker, refer to Official Docker Documentation.
If you have any questions, please contact us in the following ways:
WeChat: sn0wdr1am86
WeChat group: add the above WeChat, remark the WeChat group
QQ: 3217680847
QQ Group: 82695646
Recommended Posts