Environmental Science:
- Ubuntu 20.04 (LTS)
- Intel i7 9750H
1, Installing Docker using warehouse
Official description: Use the warehouse to complete the installation of Docker
If you are installing Docker for the first time, you need to set the Docker warehouse before installing Docker through the warehouse.
1. Set warehouse
1. Update apt package index and install package to allow apt to use HTTPS Repository:
$ sudo apt-get update $ sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release
2. Add the official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3. Configure a stable warehouse:
$ echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2. Install Docker Engine
1. Install the latest version of Docker Engine:
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io Reading package list... complete Analyzing dependency tree for package Reading status information... complete The following software will also be installed: docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns Recommended installation: aufs-tools cgroupfs-mount | cgroup-lite The following [new] packages will be installed: containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin libslirp0 pigz slirp4netns 0 packages have been upgraded and 8 packages have been newly installed. To uninstall 0 packages, 1 package has not been upgraded. Need to download 96.7 MB Archive of. 406 will be consumed after decompression MB Extra space. Do you want to continue? [Y/n] obtain:1 http://mirrors.aliyun.com/ubuntu groovy/universe amd64 pigz amd64 2.4-1 [57.4 kB] obtain:2 http://mirrors.aliyun.com/ubuntu groovy-updates/main amd64 libslirp0 amd64 4.3.1-1ubuntu0.1 [55.6 kB] obtain:3 https://download.docker.com/linux/ubuntu groovy/stable amd64 containerd.io amd64 1.4.9-1 [24.7 MB] obtain:4 http://mirrors.aliyun.com/ubuntu groovy/universe amd64 slirp4netns amd64 1.0.1-1 [33.1 kB] obtain:5 https://download.docker.com/linux/ubuntu groovy/stable amd64 docker-ce-cli amd64 5:20.10.8~3-0~ubuntu-groovy [38.8 MB] obtain:6 https://download.docker.com/linux/ubuntu groovy/stable amd64 docker-ce amd64 5:20.10.8~3-0~ubuntu-groovy [21.2 MB] obtain:7 https://download.docker.com/linux/ubuntu groovy/stable amd64 docker-ce-rootless-extras amd64 5:20.10.8~3-0~ubuntu-groovy [7,913 kB] obtain:8 https://download.docker.com/linux/ubuntu groovy/stable amd64 docker-scan-plugin amd64 0.8.0~ubuntu-groovy [3,889 kB] Downloaded 96.7 MB,It takes 11 seconds (8,681 kB/s) Selecting unselected packages pigz. (Reading database ... The system currently has 192110 files and directories installed.) Ready to unzip .../0-pigz_2.4-1_amd64.deb ... Decompressing pigz (2.4-1) ... Selecting unselected packages containerd.io. Ready to unzip .../1-containerd.io_1.4.9-1_amd64.deb ... Decompressing containerd.io (1.4.9-1) ... Selecting unselected packages docker-ce-cli. Ready to unzip .../2-docker-ce-cli_5%3a20.10.8~3-0~ubuntu-groovy_amd64.deb ... Decompressing docker-ce-cli (5:20.10.8~3-0~ubuntu-groovy) ... Selecting unselected packages docker-ce. Ready to unzip .../3-docker-ce_5%3a20.10.8~3-0~ubuntu-groovy_amd64.deb ... Decompressing docker-ce (5:20.10.8~3-0~ubuntu-groovy) ... Selecting unselected packages docker-ce-rootless-extras. Ready to unzip .../4-docker-ce-rootless-extras_5%3a20.10.8~3-0~ubuntu-groovy_amd64.deb ... Decompressing docker-ce-rootless-extras (5:20.10.8~3-0~ubuntu-groovy) ... Selecting unselected packages docker-scan-plugin. Ready to unzip .../5-docker-scan-plugin_0.8.0~ubuntu-groovy_amd64.deb ... Decompressing docker-scan-plugin (0.8.0~ubuntu-groovy) ... Selecting unselected packages libslirp0:amd64. Ready to unzip .../6-libslirp0_4.3.1-1ubuntu0.1_amd64.deb ... Decompressing libslirp0:amd64 (4.3.1-1ubuntu0.1) ... Selecting unselected packages slirp4netns. Ready to unzip .../7-slirp4netns_1.0.1-1_amd64.deb ... Decompressing slirp4netns (1.0.1-1) ... Setting docker-scan-plugin (0.8.0~ubuntu-groovy) ... Setting containerd.io (1.4.9-1) ... Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service. Setting docker-ce-cli (5:20.10.8~3-0~ubuntu-groovy) ... Setting libslirp0:amd64 (4.3.1-1ubuntu0.1) ... Setting pigz (2.4-1) ... Setting docker-ce-rootless-extras (5:20.10.8~3-0~ubuntu-groovy) ... Setting slirp4netns (1.0.1-1) ... Setting docker-ce (5:20.10.8~3-0~ubuntu-groovy) ... Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service. Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket. Processing for systemd (246.6-1ubuntu1.7) Trigger for ... Processing for man-db (2.9.3-2) Trigger for ... Processing for libc-bin (2.32-0ubuntu3) Trigger for ...
2. Or install the specified version of Docker Engine:
$ apt-cache madison docker-ce docker-ce | 5:20.10.8~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.7~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.6~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.5~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.4~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.3~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.2~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.1~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages docker-ce | 5:20.10.0~3-0~ubuntu-groovy | https://download.docker.com/linux/ubuntu groovy/stable amd64 Packages $ sudo apt-get install docker-ce=5:20.10.4~3-0~ubuntu-groovy docker-ce-cli=5:20.10.4~3-0~ubuntu-groovy containerd.io
3. Verify whether Docker Engine is installed correctly by running the Hello world image:
$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685 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/
- Sometimes it will get stuck after executing the command. Just execute it after ctrl+c.
3. Simple configuration
(1) Authorize root user to manage Docker
After installing Docker Engine for the first time and confirming that the installation is successful, execute any docker command, and the following errors may be displayed:
This is because the Docker daemon is bound to Unix sockets instead of TCP ports. By default, Unix sockets are owned by root.
Solution 1: ordinary users add sudo before the docker command.
Solution 2: create a Unix group named Docker and add users to it. When the Docker daemon starts, it creates a Unix socket that can be accessed by Docker group members.
$ sudo groupadd docker # Create user group $ sudo usermod -aG docker $USER # Add current user to user group $ newgrp docker # Activate user group change $ docker run hello-world # Then ordinary users can run the docker command
(2) Startup and self startup of Docker service
Startup and self startup:
$ sudo systemctl enable docker.service $ sudo systemctl enable containerd.service
- On Ubuntu, the Docker service is configured to start automatically by default.
Turn off startup and self startup:
$ sudo systemctl disable docker.service $ sudo systemctl disable containerd.service
Start service:
$ sudo service docker start
Shut down service:
$ sudo service docker stop
Restart service:
$ sudo service docker restart
Accessible Linux postinstall To view more service configurations after installing docker on Linux.
2, Installing Docker using package
1. Download the. deb file
visit https://download.docker.com/linux/ubuntu/dists/ , select the. deb file that matches the Ubuntu version.
2. Install Docker Engine
sudo dpkg -i /path/to/package.deb # Point to the path where the. deb file is located
- Automatically start the Docker daemon.
3, Uninstall Docker
1. Uninstall the old version of Docker
$ sudo apt-get remove docker docker-engine docker.io containerd runc
The contents of / var/lib/docker / will be retained, including images, containers, Mount volumes, and network configuration.
2. Completely uninstall Docker
1. Completely uninstall Docker:
$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
2. Further uninstall related files:
$ sudo rm -rf /var/lib/docker $ sudo rm -rf /var/lib/containerd
- You must manually delete any edited profiles.
4, Update Docker
Method 1: install Docker with package.
Method 2: uninstall the old version, and then use the warehouse to install Docker