docker 部署的 jenkins 正确迁移到新服务器

问题: docker 部署的 jenkins 在迁移时如果只迁移 jenkins_home 目录到新服务器上,在新服务器上部署 jenkins 后在使用中会遇到任务无法正常构建、系统奔溃报错。解决办法就是将镜像也一并迁移。

镜像迁移

  • 旧服务器导出镜像
bash 复制代码
# 根据容器创建新镜像
docker commit jenkins my/jenkins:1.0.0
# 导出镜像
docker save -o my-jenkins.tar my/jenkins:1.0.0
  • 新服务器导入镜像
bash 复制代码
# 新环境中导入镜像
docker load -i my-jenkins.tar
# 新环境中 jenkins_home 目录添加权限
sudo chown -R 1000:1000 /u01/jenkins_home
  • docker-compose.yml
yml 复制代码
version: '3'
services:
  jenkins:
    image: my/jenkins:1.0.0
    container_name: jenkins
    restart: always
    network_mode: "host"
    privileged: true
    volumes:
      - /etc/localtime:/etc/localtime
      - /u01/jenkins_home:/var/jenkins_home
    environment:
      JAVA_OPTS: "-Duser.timezone=Asia/Shanghai"
      JENKINS_OPTS: "--prefix=/jenkins --httpPort=8000"
      JENKINS_ARGS: "--prefix=/jenkins"
  • 部署 jenkins
bash 复制代码
docker-compose up -d jenkins

用私有镜像仓库更方便,该方法针对没有镜像仓库的同学。

网易云镜像仓库:https://c.163.com/hub#/m/home/

相关推荐
IMPYLH2 小时前
Linux 的 pinky 命令
linux·运维·服务器·bash
HelloWorld_SDK3 小时前
Docker安装OpenClaw
运维·docker·容器·openclaw
REDcker3 小时前
Linux iptables 与 Netfilter:原理、路径与运维要点
linux·运维·服务器
无忧.芙桃6 小时前
进程控制(上)
linux·运维·服务器
航Hang*7 小时前
Windows Server 配置与管理——第8章:配置Web服务器
运维·服务器·windows·学习·vmware
hweiyu007 小时前
Linux命令:suspend
linux·运维·服务器
code_li8 小时前
服务器与普通PC区别?
运维·服务器
小天互连即时通讯8 小时前
中小企业本地部署即时通讯:预算有限怎么把功能配齐
运维·服务器·网络
cyber_两只龙宝8 小时前
【Docker】Docker的资源限制
linux·运维·服务器·docker·云原生·容器
XDHCOM8 小时前
Docker怎么设置Redis?
redis·docker·容器