1截酷、查看環(huán)境
此處在Centos7進(jìn)行安裝,可以使用以下命令查看CentOS版本
rpm -q centos-release
在 CentOS 7安裝docker要求系統(tǒng)為64位损姜、系統(tǒng)內(nèi)核版本為 3.10 以上,可以使用以下命令查看
uname -r
2 安裝包官方地址:https://download.docker.com/linux/static/stable/x86_64/
可以先下載到本地殊霞,然后通過ftp工具上傳到服務(wù)器上摧阅,或者在服務(wù)器上使用命令下載
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
3 解壓
tar -zxvf docker-18.06.3-ce.tgz
4 將解壓出來的docker文件復(fù)制到 /usr/bin/ 目錄下
cp docker/* /usr/bin/
5 在/etc/systemd/system/目錄下新增docker.service文件,內(nèi)容如下绷蹲,這樣可以將docker注冊為service服務(wù)
cd /etc/systemd/system
cat > docker.service
敲完上述命令會進(jìn)入 docker.service 的編輯模式棒卷,可以直接輸入你想要寫入的內(nèi)容,最后按ctrl+z退出編輯模式自動保存
將以下內(nèi)容放入到docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
此處的--insecure-registry=127.0.0.1(此處改成你私服ip)設(shè)置是針對有搭建了自己私服Harbor時允許docker進(jìn)行不安全的訪問祝钢,否則訪問將會被拒絕比规。
6 啟動docker
給docker.service文件添加執(zhí)行權(quán)限
chmod +x /etc/systemd/system/docker.service
重新加載配置文件(每次有修改docker.service文件時都要重新加載下)
systemctl daemon-reload
啟動
systemctl start docker
設(shè)置開機(jī)啟動
systemctl enable docker.service
查看docker服務(wù)狀態(tài)
systemctl status docker
上圖表示docker已安裝成功