51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Ubuntu安装docker

Ubuntu安装docker

1.卸载旧的docker版本

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do  apt-get remove $pkg; done

2.切换国内的软件源

cat > /etc/apt/sources.list <<EOF
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF

3.更新软件源及证书

apt-get update
apt-get install ca-certificates curl gnupg

4.添加Docker的官方GPG密钥

install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

chmod a+r /etc/apt/keyrings/docker.gpg

5.配置Ubuntu的docker软件源

cat > /etc/apt/sources.list.d/docker.list <<EOF
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu   focal stable
EOF

6.更新软件源

apt-get update

7.安装软件源

apt-get -y install docker-ce docker-ce-cli containerd.io

8.配置镜像加速

mkdir -p /etc/docker

tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://tuv7rqqq.mirror.aliyuncs.com"]
}
EOF

systemctl daemon-reload
systemctl restart docker

9.启动docker服务

systemctl enable --now docker

10.验证docker版本

docker version

安装成功了

docker run hello-world

Ubuntu卸载docker环境:

1.卸载软件包

apt-get -y purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

2.删除数据目录

rm -rf /var/lib/docker /var/lib/containerd
赞(5)
未经允许不得转载:工具盒子 » Ubuntu安装docker