填坑上一篇文章:如何給無(wú)法上外網(wǎng)的機(jī)器上做 docker 鏡像遷移(記錄),上一章最后留了五個(gè)問(wèn)題畦幢,先解決兩個(gè)
第一個(gè)問(wèn)題:Linux
離線環(huán)境下如何安裝 docker
- 先下好安裝包坎吻,地址在這里:https://download.docker.com/linux/static/stable/x86_64/
- 不管是 ftp 也好,肉身上傳也好宇葱,反正用你的手段就把安裝包給搞到目標(biāo)服務(wù)器
- 解壓并移動(dòng)到
/usr/bin/
目錄下瘦真,如下:
tar -zxvf docker-20.10.9.tgz
mv docker/* /usr/bin/
rm -rf docker
- 在
/etc/systemd/system/
目錄下新增docker.service
文件,將docker
注冊(cè)為service
服務(wù)黍瞧,方便設(shè)置開(kāi)機(jī)自啟
[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 --selinux-enabled=false --insecure-registry=127.0.0.1
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
- 給
service
文件運(yùn)行權(quán)限chmod +x /etc/systemd/system/docker.service
- 重新加載配置文件
systemctl daemon-reload
- 設(shè)置Docker為開(kāi)機(jī)自啟
systemctl enable docker.service
- 啟動(dòng)Docker容器
systemctl start docker
附:Linux
離線環(huán)境下如何安裝 docker-compose
- 同上诸尽,下載安裝包:https://github.com/docker/compose/releases,注意:
docker
與docker-compose
版本需兼容印颤,否則啟動(dòng)容器將失敗 - 同上您机,把安裝包給搞到目標(biāo)服務(wù)器
/usr/local/bin/
中,并重命名為:docker-compose
- 給權(quán)限
chmod +x /usr/local/bin/docker-compose
- 查看是否安裝成功年局,如果不成功可以試試重啟
docker-compose -v
第二個(gè)問(wèn)題:鏡像有了际看,如何使用 docker-compose
快速搭建本地環(huán)境
導(dǎo)入鏡像后正常使用就行,docker-compose
判斷本地鏡像有了之后會(huì)默認(rèn)從本地鏡像展開(kāi)容器矢否,不會(huì)重新下載