填坑上一篇文章:如何给无法上外网的机器上做 docker 镜像迁移(记录),上一章最后留了五个问题,先解决两个
第一个问题:Linux
离线环境下如何安装 docker
- 先下好安装包,地址在这里:https://download.docker.com/linux/static/stable/x86_64/
- 不管是 ftp 也好,肉身上传也好,反正用你的手段就把安装包给搞到目标服务器
- 解压并移动到
/usr/bin/
目录下,如下:
tar -zxvf docker-20.10.9.tgz
mv docker/* /usr/bin/
rm -rf docker
- 在
/etc/systemd/system/
目录下新增docker.service
文件,将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 --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
文件运行权限chmod +x /etc/systemd/system/docker.service
- 重新加载配置文件
systemctl daemon-reload
- 设置Docker为开机自启
systemctl enable docker.service
- 启动Docker容器
systemctl start docker
附:Linux
离线环境下如何安装 docker-compose
- 同上,下载安装包:https://github.com/docker/compose/releases,注意:
docker
与docker-compose
版本需兼容,否则启动容器将失败 - 同上,把安装包给搞到目标服务器
/usr/local/bin/
中,并重命名为:docker-compose
- 给权限
chmod +x /usr/local/bin/docker-compose
- 查看是否安装成功,如果不成功可以试试重启
docker-compose -v
第二个问题:镜像有了,如何使用 docker-compose
快速搭建本地环境
导入镜像后正常使用就行,docker-compose
判断本地镜像有了之后会默认从本地镜像展开容器,不会重新下载