How to install Docker on Ubuntu 20.04 Linux

Docker is an application used to simplify the application management process in a container. The container uses a process isolated from resources to run applications. Docker allows you to build, test, and deploy an application so that it can run almost anywhere.
It is similar to a virtual machine, more flexible, more resource-friendly, more portable, and more dependent on the host operating system. It is a platform environment used to run a single application, which includes everything needed for the software to run.
Today, Docker is known as a modern software management platform, including DevOps continuous integration, deployment and production management.
In this tutorial, you will learn to install Docker on Ubuntu 20.04 Linux system.
The Docker package is available under the Ubuntu 20.04 repository, but it may not have the latest version. So, we will install the latest Docker here by using Docker's official repository.
Installing Docker on Ubuntu 20.04 It is
very easy to install Docker on Ubuntu system or server. Please enable Docker repository and install the package after importing the repository GPG key.
In the first step, we will update the package list and install the dependencies needed to add a new HTTPS repository:

$ sudo apt update
$ sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Now, use the following curl command to import the GPG key of the Docker repository: After
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
importing the GPG key, you need to add the APT repository of Docker with the following command:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Now, the Docker repository is enabled in your system; you can install the current repository Any version of Docker available in.
Installing the latest version of Docker
To install the latest version of Docker, you can use the following command, but if you want to install any specific version of Docker you want to install, you should skip this step and move on to the next version.

$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io

Installing a specific version of Docker
To install a specific version of Docker, you should list the available Docker versions in the repository. To get a list of available versions of Docker, use the following command:

# sudo apt update
# apt list -a docker-ce

You will get the available Docker version in the command output in the second column.

output:
docker-ce/focal 5:19.03.9~3-0~ubuntu-focal amd64

You can use "= <version>" after the package name to refer to the version to install a specific version of Docker on your Ubuntu computer, as shown in the following example: After a
$ sudo apt install docker-ce=&lt;VERSION&gt; docker-ce-cli=&lt;VERSION&gt; containerd.io
successful installation, the Docker service will automatically start. To verify the Docker service status, use the following command:
$ sudo systemctl status docker
output should look like this:

output:
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-05-21 14:47:34 UTC; 42s ago
...

When your machine uses a new version of Docker, you can use the following standard commands to update:
$ sudo apt update && sudo apt upgrade
If you don’t want to automatically update Docker, you should mark it as blocked to prevent updates with the following command:
$ sudo apt-mark hold docker-ce
Execute as a non-root user Docker commands
Docker commands can only be executed by the root user and users with sudo privileges.
If you want to execute Docker commands by a non-root user, you first need to add the user to the docker group created during the installation of the Docker CE package.
You can use the following command to add users to the docker group:
$ sudo usermod -aG docker $USER
You should replace "$USER" with the username.
Create a new user session to refresh the group membership, the user can execute the docker command.
Verifying the Docker installation
To verify the Docker installed in the system, you can execute the docker command without using sudo. We will run a test container:
$ docker container run hello-world
if it is not available locally, the above command will download the test image. After downloading, run it in the container, print the "Hello from Docker" message and exit.
You will get output similar to the following:
The test container will stop after printing the message because it does not have a long-running process.
The Docker command pulls the image from Docker Hub; it is the default cloud-based Docker registry service with all other features including storing Docker images in private and public repositories.
Uninstall Docker
To uninstall Docker from your computer, always delete all containers, images, volumes, and networks.
You can stop all running containers and delete all docker objects with the following command:

$ docker container stop $(docker container ls -aq)
$ docker system prune -a --volumes

Now, you can use the apt package manager to uninstall Docker packages from the Ubuntu system, just like other packages:

$ sudo apt purge docker-ce
$ sudo apt autoremove

Now you have learned to install Docker on an Ubuntu 20.04 Linux machine, and you also learned to execute docker commands and run Docker containers. A5 Internet https://www.a5idc.net/

Guess you like

Origin blog.51cto.com/14414732/2536353