1. yum安装
#源添加
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum clean all
yum install -y bash-completion.noarch
# 安装指定版版本
yum -y install docker-ce-18.09.9-3.el7
#也可以查看版本安装
#yum list docker-ce --showduplicates | sort -r
#启动docker
systemctl enable docker
systemctl start docker
systemctl status docker
2. 离线版安装[复制粘贴一键搭建,不整那么多花里胡哨的]
#官方下载docker
#https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz
#个人网站下载:
cd /root
wget https://www.chenleilei.net/soft/docker/docker-19.03.9.tgz
tar zxvf docker-19.03.9.tgz
mv docker/* /usr/bin
#加入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
#--------------------------------------------------------
#创建配置文件
rm -f /etc/docker/*
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ajvcw8qn.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl enable docker.service
#个人docker源:
#这个是阿里云配置的加速,直接添加阿里云加速源就可以了,上面显示了配置办法。
#https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
#设置开机启动和启动即可
systemctl enable docker
systemctl start docker