# Uninstall old versions$ apt-get remove docker docker-engine docker.io containerd runc# Install using the repository# 1.Set up the repository$ apt-get update$ apt-get install \apt-transport-https \ca-certificates \curl \gnupg \lsb-release# 2.Add Docker’s official GPG key:$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg# 3.Use the following command to set up the stable repository$ echo \"deb [arch=amd64 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# Install Docker Engine# 1.Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:$ apt-get update$ apt-get install docker-ce docker-ce-cli containerd.io# 2.To install a specific version of Docker Engine, list the available versions in the repo, then select and install:# a. List the versions available in your repo:$ apt-cache madison docker-ce# b. Install a specific version using the version string from the second column, for example,$ apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io# 3.Verify that Docker Engine is installed correctly by running the hello-world image.$ docker run hello-world# Uninstall Docker Engine# 1.Uninstall the Docker Engine, CLI, and Containerd packages:$ apt-get purge docker-ce docker-ce-cli containerd.io# 2.Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:$ rm -rf /var/lib/docker$ rm -rf /var/lib/containerd
# 一旦安装完成,Docker 服务将会自动启动。你可以输入下面的命令,验证它:
$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-05-11 14:10:30 CST; 9min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 25797 (dockerd)
Tasks: 26
Memory: 66.6M
CGroup: /system.slice/docker.service
└─25797 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
5月 11 14:10:29 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:29.684165258+08:00" level=warning msg="Your kernel does not support cgroup blkio weight"
5月 11 14:10:29 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:29.684173928+08:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
5月 11 14:10:29 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:29.684348901+08:00" level=info msg="Loading containers: start."
5月 11 14:10:30 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:30.324585115+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip>"
5月 11 14:10:30 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:30.843583889+08:00" level=info msg="Loading containers: done."
5月 11 14:10:30 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:30.890713738+08:00" level=info msg="Docker daemon" commit=8728dd2 graphdriver(s)=overlay2 version=20.10.6
5月 11 14:10:30 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:30.890828850+08:00" level=info msg="Daemon has completed initialization"
5月 11 14:10:30 chia-ubuntu systemd[1]: Started Docker Application Container Engine.
5月 11 14:10:30 chia-ubuntu dockerd[25797]: time="2021-05-11T14:10:30.927636828+08:00" level=info msg="API listen on /run/docker.sock"
5月 11 14:14:25 chia-ubuntu dockerd[25797]: time="2021-05-11T14:14:25.611048478+08:00" level=info msg="ignoring event" container=2218960bbc12c5e3783ecb5170ebb9ea4405a27cedab8fc2e67a48fa56109fcb>
# 如果你想阻止 Docker 自动更新,锁住它的版本:
$ apt-mark hold docker-ce
$ docker info
$ docker version
以非 Root 用户身份执行 Docker
默认情况下,只有 root 或者 有 sudo 权限的用户可以执行 Docker 命令。
想要以非 root 用户执行 Docker 命令,你需要将你的用户添加到 Docker 用户组,该用户组在 Docker CE 软件包安装过程中被创建。想要这么做,输入:
sudo usermod -aG docker $USER
$USER是一个环境变量,代表当前用户名。
登出,并且重新登录,以便用户组会员信息刷新。
