How to install and use Docker on Ubuntu 20.04

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.

1. Install Docker on Ubuntu 20.04

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.

  1. To install the latest version of Docker, run the following command. If you want to install the specified version, skip this step and skip to the next step.
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
  1. To install a specific version, first list all available versions in the Docker software source:
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 &amp;&amp; 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

2. Execute Docker as a non-Root user

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.

Three, verify the installation process##

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.

Fourth, uninstall Docker

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

Five, summary##

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

How to install and use Docker on Ubuntu 20.04
How to install and use Docker on Ubuntu 16.04
How to install and use Docker on CentOS 7
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install and use MySQL Workbench on Ubuntu 18.04
How to install Docker Compose on Ubuntu 18.04
How to install Prometheus with Docker on Ubuntu 14.04
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure NATS on Ubuntu 16.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
How to use Docker data volumes on Ubuntu 14.04
How to install and use Composer on CentOS 8
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and use Curl on CentOS 8
How to install and configure AppScale on Ubuntu 12.04
How to install and configure PostGIS on Ubuntu 14.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04