實(shí)際項(xiàng)目開發(fā)過程中芥永,客戶環(huán)境大多是全內(nèi)網(wǎng)環(huán)境庄蹋,無法連接互聯(lián)網(wǎng)奄侠。這樣docker就不能yum在線聯(lián)網(wǎng)安裝卓箫,所需要的鏡像也不能在線pull下載。這時(shí)就需要進(jìn)行離線安裝docker及鏡像垄潮。
1烹卒、下載docker安裝文件
離線安裝docker,需要下載docker的安裝文件弯洗。
地址:https://download.docker.com/linux/static/stable/x86_64/
我下的是最新的版本[docker-19.03.6.tgz]旅急,文件不大,只有60M左右牡整。
2藐吮、離線docker安裝
將安裝包文件上傳到服務(wù)器目錄并解壓。
[root@iZbp13sno1lc2yxlhjc4b3Z ~]#tar -xvf docker-19.03.6.tar
將解壓出來的docker文件內(nèi)容移動(dòng)到 /usr/bin/ 目錄下
[root@iZbp13sno1lc2yxlhjc4b3Z ~]#cp docker/* /usr/bin/
將docker注冊(cè)為service,在/etc/systemd/system目錄下創(chuàng)建docker.service文件谣辞,并配置如下內(nèi)容保存迫摔。
[root@iZbp13sno1lc2yxlhjc4b3Z ~]#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
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
添加文件權(quán)限并啟動(dòng)docker,執(zhí)行如下命令:
chmod +x /etc/systemd/system/docker.service #添加文件權(quán)限
systemctl daemon-reload #重載unit配置文件
systemctl start docker #啟動(dòng)Docker
systemctl enable docker.service #設(shè)置開機(jī)自啟
驗(yàn)證docker安裝是否成功:
systemctl status docker #查看Docker狀態(tài)
docker -v #查看Docker版本
Docker離線安裝好后泥从,下面我們把鏡像導(dǎo)入到Docker句占。
3、離線鏡像文件導(dǎo)入
內(nèi)網(wǎng)環(huán)境沒法pull鏡像躯嫉,但是docker本身可以將已有的鏡像導(dǎo)出成tar文件纱烘,并且可以再次導(dǎo)入到docker,利用這一點(diǎn)祈餐,可以實(shí)現(xiàn)離線鏡像文件的下載凹炸。
找一臺(tái)可以聯(lián)網(wǎng)的docker機(jī)器,并pull下載需要的鏡像文件昼弟。
然后使用如下命令將鏡像文件導(dǎo)出:
docker save java:8 -o java.tar #將java 8的鏡像導(dǎo)出成tar文件
將tar文件上傳到內(nèi)網(wǎng)docker服務(wù)器啤它,使用如下命令導(dǎo)入鏡像文件:
docker load -i java.tar
查看導(dǎo)入的鏡像文件:
[root@iZbp13sno1lc2yxlhjc4b3Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java 8 d23bdf5b1b1b 3 years ago 643MB
OK,通過上述方式舱痘,實(shí)現(xiàn)了內(nèi)網(wǎng)環(huán)境下docker的安裝和鏡像文件下載变骡。后續(xù)我們就可以愉快的使用docker來部署管理我們的應(yīng)用了。