Docker几种安装方式

若机器已安装 docker 程序,请卸载它们以及相关的依赖项

yum -y remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

(Centos ) RPM 安装

# 下载rpm要安装的Docker版本的文件:  https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
# 可能需要依赖包,不推荐
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-19.03.9-3.el7.x86_64.rpm
yum install docker-ce-19.03.9-3.el7.x86_64.rpm
systemctl start docker

(Centos ) YUM 安装

sudo yum update -y
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo docker --version
sudo usermod -aG docker $USER

脚本安装

# 官方安装脚本
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

# 国内daocloud一键安装命令
curl -sSL https://get.daocloud.io/docker | sh

#  Rancher 下 docker 脚本
curl https://releases.rancher.com/install-docker/18.09.sh | sh
systemctl restart docker && systemctl enable docker 

源码安装

# 1.下载源码包
wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz
tar zxvf docker-19.03.9.tgz 
mv docker/* /usr/bin

# 2.systemd管理服务
cat > /usr/lib/systemd/system/docker.service << EOF 
[Unit] 
Description=Docker Application Container Engine 
Documentation=https://docs.docker.com 
After=network-online.target firewalld.service 
Wants=network-online.target 

[Service] 
Type=notify 
ExecStart=/usr/bin/dockerd 
ExecReload=/bin/kill -s HUP $MAINPID 
LimitNOFILE=infinity 
LimitNPROC=infinity 
LimitCORE=infinity 
TimeoutStartSec=0 
Delegate=yes 
KillMode=process 
Restart=on-failure 
StartLimitBurst=3 
StartLimitInterval=60s 

[Install] 
WantedBy=multi-user.target 
EOF


# 3.镜像加速
mkdir /etc/docker 
cat > /etc/docker/daemon.json << EOF 
{
	"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF

# 启动开机自启
systemctl daemon-reload && systemctl start docker && systemctl enable docker

Last updated