2. Use Xshell to connect to the remote server for operation
#The system kernel is above 3.10 zzw@zzw-virtual-machine:~$ uname -r 3.10.0-1062.12.1.e17.x86_64 zzw@zzw-virtual-machine:~$ cat /etc/os-release NAME="Ubuntu" VERSION="20.04.2 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.2 LTS" VERSION_ID="20.04" HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" VERSION_CODENAME=focal UBUNTU_CODENAME=focal
Automatic installation using official installation script
The installation commands are as follows:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
You can also use the domestic daocloud one click installation command:
curl -sSL https://get.daocloud.io/docker | sh
Uninstall old version
The old version of docker is called docker, docker IO or docker engine. If installed, uninstall them:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
It is currently called docker engine community software package docker CE.
There are two ways to install docker engine community.
Use Docker warehouse for installation
Before installing Docker engine community on the new host for the first time, you need to set up the Docker warehouse. After that, you can install and update Docker from the warehouse.
Set up warehouse
Update apt package index.
$ sudo apt-get update
Install apt dependency package to obtain the warehouse through HTTPS:
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
Add the official GPG key of Docker: (if Alibaba cloud warehouse is used, look down and skip the current step and use Alibaba cloud key)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ $(lsb_release -cs) \ stable"
Use the following instructions to set up the stable version warehouse (if Alibaba cloud image is recommended, Alibaba cloud key must be used)
#If Alibaba cloud image is recommended, you must use Alibaba cloud key $ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - $ sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
Install docker engine community
Update apt package index.
$ sudo apt-get update
Install the latest version of docker engine community and containerd, or go to the next step to install a specific version:
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
To install a specific version of docker engine community, list the available versions in the warehouse and select an installation. List the versions available in your warehouse:
$ apt-cache madison docker-ce docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~ubuntu | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~ubuntu | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial/stable amd64 Packages
Use the version string in the second column to install a specific version, for example, 5:18.09.13-0ubuntu xenial.
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
Test whether Docker is successfully installed. Enter the following instructions and print out the following information to ensure successful installation:
$ sudo docker run hello-world 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/
Install using Shell script
Docker is get.docker.com and test.docker.com A convenient script is provided on to quickly install the edge version and test version of docker engine community. The source code of the script is in the docker install repository. It is not recommended to use these scripts in a production environment. Before using them, you should understand the potential risks:
- The script needs to run root or have sudo privileges. Therefore, you should carefully check and review the script before running it.
- These scripts try to detect the Linux distribution and version and configure the package management system for you. In addition, the script does not allow you to customize any installation parameters. From the perspective of Docker or your own organization's guidelines and standards, this may lead to unsupported configurations.
- These scripts will install all dependencies and recommendations of the package manager without confirmation. Depending on the current configuration of the host, a large number of software packages may be installed.
- The script does not provide an option to specify which version of Docker to install, but installs the latest version published in the edge channel.
- If other mechanisms have been used to install Docker on the host, please do not use convenient scripts.
This example uses get.docker.com The script on installs the latest version of docker engine community on Linux. To install the latest test version, use test instead docker. com. In each of the following commands, test is used instead of get every time.
$ curl -fsSL https://get.docker.com -o get-docker.sh $ sudo sh get-docker.sh
If you want to use docker as a non root user, you should consider adding users to the docker group in a manner similar to the following:
$ sudo usermod -aG docker your-user
To delete an installation package:
sudo apt-get purge docker-ce
Delete image, container, configuration file and other contents:
sudo rm -rf /var/lib/docker