Linux 離線安裝docker(一鍵式安裝)

前言

有時候會遇到服務(wù)器不能聯(lián)網(wǎng)的情況,這樣就沒法用yum安裝軟件,docker也是如此,針對這種情況,總結(jié)了一下離線安裝docker的步驟,分享給大家
1. 準(zhǔn)備docker離線包

docker官方離線包下載地址
下載需要安裝的docker版本,我此次下載的是
docker-17.03.2-ce.tgz版本

2. 準(zhǔn)備docker.service 系統(tǒng)配置文件

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
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
3. 準(zhǔn)備安裝腳本和卸載腳本

安裝腳本 install.sh

#!/bin/sh
echo '解壓tar包...'
tar -xvf $1

echo '將docker目錄移到/usr/bin目錄下...'
cp docker/* /usr/bin/

echo '將docker.service 移到/etc/systemd/system/ 目錄...'
cp docker.service /etc/systemd/system/

echo '添加文件權(quán)限...'
chmod +x /etc/systemd/system/docker.service

echo '重新加載配置文件...'
systemctl daemon-reload

echo '啟動docker...'
systemctl start docker

echo '設(shè)置開機自啟...'
systemctl enable docker.service

echo 'docker安裝成功...'
docker -v

卸載腳本 uninstall.sh

#!/bin/sh

echo '刪除docker.service...'
rm -f /etc/systemd/system/docker.service

echo '刪除docker文件...'
rm -rf /usr/bin/docker*

echo '重新加載配置文件'
systemctl daemon-reload

echo '卸載成功...'
4. 安裝
  • 4.1 此時目錄為:(只需要關(guān)注docker-17.03.2-ce.tgz、docker.service、install.sh、uninstall.sh即可)


    1.PNG
  • 4.2 執(zhí)行腳本 sh install.sh docker-17.03.2-ce.tgz
    執(zhí)行過程如下:
    2.PNG

待腳本執(zhí)行完畢后,執(zhí)行docker -v
發(fā)現(xiàn)此時docker已安裝成功,可以用docker --help 查看docker命令,從現(xiàn)在開始你就可以自己安裝image和container了

  • 4.3 如果你想卸載docker,此時執(zhí)行腳本 sh uninstall.sh即可,執(zhí)行過程如下:
    3.PNG

    此時輸入docker -v,發(fā)現(xiàn)docker已經(jīng)卸載
多次動手操作以后,發(fā)現(xiàn)docker離線安裝如此方便,希望對你有所幫助
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容