大虾

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

将脚本保存为docker_install.sh,可以上传git,到服务器中,git clone下来后,sh docker_install.sh即可自动安装

ubuntu实现

# 以Ubuntu为例
# Step 1: 移除之前docker版本并更新更新 apt 包索引
sudo apt-get remove docker docker-engine docker.io
sudo apt-get update

# Step 2: 安装 apt 依赖包,用于通过HTTPS来获取仓库
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

# Step 3: 添加 Docker 的官方 GPG 密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

# Step 4: 设置docker稳定版仓库,这里使用了阿里云仓库
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update

# Step 5: 安装免费的docker Community版本docker-ce
sudo apt-get -y install docker-ce
# sudo apt-get install -y docker-ce=<VERSION> #该命令可以选择docker-ce版本

# Step 6: 查看docker版本及运行状态
sudo docker -v
sudo systemctl status docker

# Step 7:本步非必需。使用阿里云设置Docker镜像加速,注意下面链接请使用阿里云给自己的URL
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{ "registry-mirrors": ["https://ua3456xxx.mirror.aliyuncs.com"] }
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

centos实现

yum update -y
yum install docker -y

cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

# 基础环境配置 卸载旧的docker 安装新的yum依赖
yum remove docker docker-common docker-selinux docker-engine
yum install yum-utils device-mapper-persistent-data lvm2 -y

# 注意 -O 是大写的字母O
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#g' /etc/yum.repos.d/docker-ce.repo
yum makecache fast

# 安装免费的社区版docker-ce
yum install docker-ce -y

# 启动docker
systemctl start docker

可能出现的错误

如果出现错误:

This system is not registered with an entitlement server. You can use subscription-manager to register.

解决办法:

[root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=0 # 把1改为0 保存
posted on 2023-04-15 17:27  一灯编程  阅读(1101)  评论(0编辑  收藏  举报