Docker Plugin for Jenkins Pipeline - No user exists for uid 1005

前端 未结 4 687
囚心锁ツ
囚心锁ツ 2021-02-12 23:10

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

4条回答
  •  清酒与你
    2021-02-12 23:29

    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 [...]
    

    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"
          }
        }
      }
    }
    

提交回复
热议问题