由於網絡隔離的原因,部分服務器如數據庫服務器沒有互聯網訪問環境,需要離線安裝docker.
- 一、離線下載docker, 選擇最新版本的Ce版本就好,
Docker CE是免費的Docker產品的新名稱,Docker CE包含了完整的Docker平臺,非常適合開發人員和運維團隊構建容器APP。
https://download.docker.com/linux/static/stable/x86_64/
- 二、 sftp上傳到目標服務器(過程略)
- 三、解壓文件
#tar -xvf docker-18.06.3-ce.tar
- 四、複製文件到 /usr/bin
#cp docker/* /usr/bin/
複製到 /usr/bin 相當於配置了path,命令終端裏能調用 docker 命令。
- 五、配置docker
由於是離線安裝,所以需要手動添加 docker.service配置文件。
修改一下docker默認鏡像和容器在系統中的磁盤目錄
注意這一行要改成自己的配置
ExecStart=/usr/bin/dockerd --graph=/MysqlDb/docker --storage-driver=overlay
# Docker默認的鏡像和容器存儲位置在/var/lib/docker中
# 修改docker.service文件,指定鏡像倉庫目錄
vim /etc/systemd/system/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 --graph=/MysqlDb/docker --storage-driver=overlay --registry-mirror=https://s42tycw4.mirror.aliyuncs.com 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
- 六、啓動Docker
chmod +x /etc/systemd/system/docker.service #添加文件權限並啓動docker
systemctl daemon-reload #重載unit配置文件
systemctl start docker #啓動Docker
systemctl enable docker.service #設置開機自啓
- 七、驗證
systemctl status docker #查看Docker狀態
docker -v #查看Docker版本