ubuntu20.04 LTS Method Steps for Installing docker

  • 2021-08-17 01:25:08
  • OfStack

Zero: Uninstall the old version

Older versions of Docker are called docker, docker. io, or docker-engine. If installed, uninstall them:


$ sudo apt-get remove docker docker-engine docker.io containerd runc

Currently known as the Docker Engine-Community package docker-ce.

1: Set up the warehouse

The Docker repository needs to be set up before the first installation of Docker Engine-Community on the new host. After that, you can install and update Docker from the repository.

Update the apt packet index.


$ sudo apt-get update

Install the apt dependency package to get the repository through HTTPS:


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

Add the official GPG key for Docker:


$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 Verifies that you now have a key with the fingerprint by searching the last 8 characters of the fingerprint.


$ sudo apt-key fingerprint 0EBFCD88
 
pub rsa4096 2017-02-22 [SCEA]
  9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid   [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]

Use the following instructions to set up the stable repository

Note: At present, there is no domestic docker source for 20.04, so version 18.04 is used temporarily.


$ sudo add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 bionic \
 stable"

2: Install Docker Engine-Community

Update the apt packet index.


$ sudo apt-get update

Install the latest versions of Docker Engine-Community and containerd


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

3: Test

Input


$ sudo docker run hello-world

If docker says hello to you-or something like this appears


Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                 Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest


Hello from Docker!
This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 (amd64)
 3. The Docker daemon created a new container from that image which runs the
 executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
 to your terminal.


To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/


For more examples and ideas, visit:
 https://docs.docker.com/get-started/

It means the installation is finished.

4: sudo-free operation & Mirror acceleration

sudo-free

Refer to the following method to add users to docke group


$ sudo apt-get update
0

Restart docker


$ sudo apt-get update
1

(However, something weird happened on my machine-I still couldn't start docker as a normal user after restarting the docker service. The sudo will not run until the machine is restarted. )

docker Mirror Acceleration

I used Alibaba Cloud's free acceleration

https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

Follow the prompts in Alibaba Cloud's webpage for subsequent settings, and will not be repeated here.

5: Reference link

-Windows10 Install WSL2 Ubuntu20.04 and set up docker environment
-Ubuntu Docker installation


Related articles: