天天看點

Docker:Linux離線安裝docker-17.03.2-ce,配置開機自啟

1. 準備docker離線包

docker官方離線包下載下傳位址

下載下傳需要安裝的docker版本,我此次下載下傳的是:docker-17.03.2-ce.tgz

2. 準備docker.service 系統配置檔案

建立docker.service

# vim 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. 準備安裝腳本和解除安裝腳本

建立安裝腳本:install.sh

# vim 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 '添加檔案權限...'
chmod +x /etc/systemd/system/docker.service
echo '重新加載配置檔案...'
systemctl daemon-reload
echo '啟動docker...'
systemctl start docker
echo '設定開機自啟...'
systemctl enable docker.service
echo 'docker安裝成功...'
docker -v      

4. 解除安裝docker腳本

建立解除安裝腳本:delete.sh

$ vim delete.sh      
#!/bin/sh
echo '删除docker.service...'
rm -rf /etc/systemd/system/docker.service
echo '删除docker檔案...'
rm -rf /usr/bin/docker*
echo '重新加載配置檔案'
systemctl daemon-reload
echo '解除安裝成功...'      

5. 安裝docker

5.1 目前目錄下的所有檔案:(藍色的docker是已經安裝完成的檔案夾)

Docker:Linux離線安裝docker-17.03.2-ce,配置開機自啟

5.2 執行腳本進行安裝

$ bash install.sh docker.tgz      

    執行過程如下:

  待腳本執行完畢後,執行

//檢視docker版本指令
$ docker -v      

  發現此時docker已安裝成功,可以用

//檢視docker所有指令
$ docker --help       

  從現在開始你就可以自己安裝image和生成container了

文章轉載至:https://www.jb51.net/article/167103.htm

-----------------------------------

作者:怒吼的蘿蔔

連結:http://www.cnblogs.com/nhdlb/

-----------------------------------