前言
有時候會遇到服務器不能聯網的情況,這樣就沒法用yum安裝軟件,docker也是如此,針對這種情況,總結了一下離線安裝docker的步驟,分享給大家
1. 準備docker離線包
docker官方離線包下載地址
下載需要安裝的docker版本,我此次下載的是
docker-17.03.2-ce.tgz版本
2. 準備docker.service 系統配置文件
docker.service[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.serviceWants=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 dockerExecStart=/usr/bin/dockerdExecReload=/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=infinityLimitNPROC=infinityLimitCORE=infinity# Uncomment TasksMax if your systemd version supports it.# Only systemd 226 and above support this version.#TasksMax=infinityTimeoutStartSec=0# set delegate yes so that systemd does not reset the cgroups of docker containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=process# restart the docker process if it exits prematurelyRestart=on-failureStartLimitBurst=3StartLimitInterval=60s[Install]WantedBy=multi-user.target
3. 準備安裝腳本和卸載腳本
安裝腳本 install.sh
#!/bin/shecho '解壓tar包...'tar -xvf $1echo '將docker目錄移到/usr/bin目錄下...'cp docker/* /usr/bin/echo '將docker.service 移到/etc/systemd/system/ 目錄...'cp docker.service /etc/systemd/system/echo '添加文件權限...'chmod +x /etc/systemd/system/docker.serviceecho '重新加載配置文件...'systemctl daemon-reloadecho '啟動docker...'systemctl start dockerecho '設置開機自啟...'systemctl enable docker.serviceecho 'docker安裝成功...'docker -v
卸載腳本 uninstall.sh
#!/bin/shecho '刪除docker.service...'rm -f /etc/systemd/system/docker.serviceecho '刪除docker文件...'rm -rf /usr/bin/docker*echo '重新加載配置文件'systemctl daemon-reloadecho '卸載成功...'
4. 安裝
4.1 此時目錄為:(只需要關注docker-17.03.2-ce.tgz、docker.service、install.sh、uninstall.sh即可)

4.2 執行腳本 sh install.sh docker-17.03.2-ce.tgz 
執行過程如下:

待腳本執行完畢后,執行 docker -v 
發現此時docker已安裝成功,可以用 docker --help 查看docker命令,從現在開始你就可以自己安裝image和container了
sh uninstall.sh
4.3 如果你想卸載docker,此時執行腳本
新聞熱點
疑難解答