Jenkins slave 的 Swarm compose 文件

Swarm compose file for Jenkins slave

我正在尝试在我的单节点群中为 jenkins/slave 到 运行 创建一个撰写文件。
我使用的图像是 jenkins/slave

与图像一起使用的 docker run 命令是 docker run -i --rm --name agent1 --init -v agent1-workdir:/home/jenkins/agent jenkins/agent java -jar /usr/share/jenkins/agent.jar -workDir /home/jenkins/agent
我的撰写文件如下所示:
('local_registry:5000/jenkins_ansible_slave' 是构建的镜像,我已将其推送到我的本地注册表)

  slave1:
    image: 'local_registry:5000/jenkins_ansible_slave'
    ports:
      - "22:22"
    init: true
    volumes:
      - "/home/user/agent:/home/jenkins/agent"
    command: "java -jar /usr/share/jenkins/agent.jar -workDir /home/jenkins/agent"
    networks:
      - net

slave1 服务未启动,我在检查服务日志时收到此错误

DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    | INFO: Using /home/jenkins/agent/remoting as a remoting work directory
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    | May 03, 2021 3:27:01 PM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    | INFO: Both error and output logs will be printed to /home/jenkins/agent/remoting
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    | Exception in thread "main" java.io.EOFException: unexpected stream termination
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    |  at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:415)
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    |  at hudson.remoting.ChannelBuilder.build(ChannelBuilder.java:360)
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    |  at hudson.remoting.Launcher.main(Launcher.java:762)
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    |  at hudson.remoting.Launcher.runWithStdinStdout(Launcher.java:710)
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    |  at hudson.remoting.Launcher.run(Launcher.java:396)
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    |  at hudson.remoting.Launcher.main(Launcher.java:296)
DEVOPS-STACK_slave1.1.vcm7tc3i0ral@local_registry    | <===[JENKINS REMOTING CAPACITY]===>rO0ABXNyABpodWRzb24ucmVtb3RpbmcuQ2FwYWJpbGl0eQAAAAAAAAABAgABSgAEbWFza3hwAAAAAAAAAf4=

知道这里出了什么问题吗?

谢谢,

添加

stdin_open: true # docker run -i
tty: true        # docker run -t

我认为这会解决您的问题。 您 docker-compose 配置应如下所示。

  slave1:
    image: 'local_registry:5000/jenkins_ansible_slave'
    ports:
      - "22:22"
    init: true
    volumes:
      - "/home/user/agent:/home/jenkins/agent"
    command: "java -jar /usr/share/jenkins/agent.jar -workDir /home/jenkins/agent"
    networks:
      - net
    stdin_open: true # docker run -i
    tty: true        # docker run -t