用于Jenkins管道的Docker插件-uid 1005不存在用户 [英] Docker Plugin for Jenkins Pipeline - No user exists for uid 1005

查看:175
本文介绍了用于Jenkins管道的Docker插件-uid 1005不存在用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Jenkins管道中的Docker容器内部执行SSH命令.我正在使用 CloudBees Docker Pipeline插件旋转容器并执行命令,然后使用 SSH代理插件来管理我的SSH密钥.这是我的Jenkinsfile的基本版本:

I'm trying to execute an SSH command from inside a Docker container in a Jenkins pipeline. I'm using the CloudBees Docker Pipeline Plugin to spin up the container and execute commands, and the SSH Agent Plugin to manage my SSH keys. Here's a basic version of my Jenkinsfile:

node {
  step([$class: 'WsCleanup'])
  docker.image('node').inside {
    stage('SSH') {
      sshagent (credentials: [ 'MY_KEY_UUID' ]) {
        sh "ssh -vvv -o StrictHostKeyChecking=no ubuntu@example.org uname -a"
      }
    }
  }
}

运行SSH命令时,出现此错误:

When the SSH command runs, I get this error:

+ ssh -vvv -o StrictHostKeyChecking=no ubuntu@example.org uname -a
No user exists for uid 1005

推荐答案

我仔细查看了日志,发现Docker Pipeline插件通过传递UID来自动告诉容器与主机上登录的同一用户一起运行作为命令行参数:

I combed through the logs and realized the Docker Pipeline Plugin is automatically telling the container to run with the same user that is logged in on the host by passing a UID as a command line argument:

$ docker run -t -d -u 1005:1005 [...]

我决定通过在每个环境中运行cat /etc/passwd来检查主机和容器中存在哪些用户.当然,每个用户的列表都不相同. 1005是主机上的jenkins用户,但是该UID在容器中不存在.为了解决此问题,我在将/etc/passwd从主机安装到容器时将其旋转:

I decided to check what users existed in the host and the container by running cat /etc/passwd in each environment. Sure enough, the list of users was different in each. 1005 was the jenkins user on the host machine, but that UID didn't exist in the container. To solve the issue, I mounted /etc/passwd from the host to the container when spinning it up:

node {
  step([$class: 'WsCleanup'])
  docker.image('node').inside('-v /etc/passwd:/etc/passwd') {
    stage('SSH') {
      sshagent (credentials: [ 'MY_KEY_UUID' ]) {
        sh "ssh -vvv -o StrictHostKeyChecking=no ubuntu@example.org uname -a"
      }
    }
  }
}

这篇关于用于Jenkins管道的Docker插件-uid 1005不存在用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆