美文网首页
如何给无法上外网的机器上做 docker 镜像迁移(2)

如何给无法上外网的机器上做 docker 镜像迁移(2)

作者: sayyid | 来源:发表于2022-11-17 14:19 被阅读0次

填坑上一篇文章:如何给无法上外网的机器上做 docker 镜像迁移(记录),上一章最后留了五个问题,先解决两个

第一个问题:Linux 离线环境下如何安装 docker

  1. 先下好安装包,地址在这里:https://download.docker.com/linux/static/stable/x86_64/
  2. 不管是 ftp 也好,肉身上传也好,反正用你的手段就把安装包给搞到目标服务器
  3. 解压并移动到 /usr/bin/ 目录下,如下:
tar -zxvf docker-20.10.9.tgz
mv docker/* /usr/bin/
rm -rf docker
  1. /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

  1. service 文件运行权限chmod +x /etc/systemd/system/docker.service
  2. 重新加载配置文件systemctl daemon-reload
  3. 设置Docker为开机自启systemctl enable docker.service
  4. 启动Docker容器systemctl start docker

附:Linux 离线环境下如何安装 docker-compose

  1. 同上,下载安装包:https://github.com/docker/compose/releases,注意:dockerdocker-compose 版本需兼容,否则启动容器将失败
  2. 同上,把安装包给搞到目标服务器 /usr/local/bin/ 中,并重命名为:docker-compose
  3. 给权限 chmod +x /usr/local/bin/docker-compose
  4. 查看是否安装成功,如果不成功可以试试重启 docker-compose -v

第二个问题:镜像有了,如何使用 docker-compose 快速搭建本地环境

导入镜像后正常使用就行,docker-compose 判断本地镜像有了之后会默认从本地镜像展开容器,不会重新下载

相关文章

网友评论

      本文标题:如何给无法上外网的机器上做 docker 镜像迁移(2)

      本文链接:https://www.haomeiwen.com/subject/xjvyxdtx.html