【问题标题】:Jenkins Pipeline Docker -- Container is Not RunningJenkins Pipeline Docker -- 容器未运行
【发布时间】:2019-03-04 14:49:33
【问题描述】:

我让 Jenkins 在 EC2 实例上运行。我在 Peered VPC 中配置了 EC2 插件,当一个作业被标记为“support_ubuntu_docker”时,它会启动一个 Jenkins 从站,并预先安装 Docker。

我能够按照示例进行操作,并让我的工作连接到在 Slave 上运行的本地 docker,并在容器内运行命令。

工作:https://pastebin.com/UANvjhnA

pipeline {
    agent {
        docker { 
            image 'node:7-alpine' 
            label 'support_ubuntu_docker'
             }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

不工作https://pastebin.com/MsSZaPha

pipeline {
    agent {
        docker { 
            image 'hashicorp/terraform:light' 
            label 'support_ubuntu_docker'
             }
    }
    stages {
        stage('Test') {
            steps {
                sh 'terraform --version'
            }
        }
    }
}

我已尝试使用 ansible/ansible:default 图像,以及我自己创建的图像。

FROM alpine:3.7
RUN apk add --no-cache terraform
RUN apk add --no-cache ansible
ENTRYPOINT ["/bin/ash"]

此图像在本地运行。

[jenkins_test] docker exec -it 3843653932c8 ash                                                                                                                                                                                                                                                   10:56:42  ☁  master ☂ ⚡ ✭
/ # terraform --version
Terraform v0.11.0

/ # ansible --version
ansible 2.4.6.0
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15 (default, Aug 22 2018, 13:24:18) [GCC 6.4.0]
/ # 

我真的只想能够克隆我的 terraform git repo,并使用容器中的 terraform 来运行我的 init/plan/applies。

我遇到的所有这些错误是。

java.io.IOException: Failed to run top 'c9dfeda21b718b9df1035500adf2ef80c5c3807cf63e724317d620d4bcaa14b3'. Error: Error response from daemon: Container c9dfeda21b718b9df1035500adf2ef80c5c3807cf63e724317d620d4bcaa14b3 is not running

【问题讨论】:

    标签: docker jenkins amazon-ec2


    【解决方案1】:

    这个问题真的应该是一个 Docker 问题; node:7-alpinehashicorp/terraform:light 有什么区别?

    hashicorp/terraform:light 有一个ENTRYPOINT 条目,指向/bin/terraform
    基本上这意味着你可以这样运行它:
    docker run hashicorp/terraform:light --version
    它会立即退出,即它不是交互式的。
    因此,如果您希望在该 Docker 容器中使用交互式 shell,则必须覆盖 ENTRYPOINT 以指向一个 shell,例如 /bin/bash,并告诉 Docker 以交互方式运行:

    pipeline {
        agent {
            docker { 
                image 'hashicorp/terraform:light' 
                args '-it --entrypoint=/bin/bash'
                label 'support_ubuntu_docker'
            }
        }
        stages {
            stage('Test') {
                steps {
                    sh 'terraform --version'
                }
            }
        }
    }
    

    【讨论】:

    • 我对此表示赞同,因为它解决了问题的根源,但这对我不起作用,而 S.Spiker 的答案有效。
    【解决方案2】:

    在脚本化管道中,您可以这样做:

    docker.image(dockerImage).inside("--entrypoint=''") {
        // code to run on container
    }
    

    如果您从已经有 ENTRYPOINT 指令的基础镜像创建要在 Jenkins 中使用的镜像,您可以通过将此行添加到您自己的 Dockerfile 的末尾来覆盖它:

    ENTRYPOINT []
    

    那么整个 --entrypoint 就不再需要了。

    【讨论】:

    • 我知道。它没有回答问题,但确实为不使用声明性管道的人添加了有用的信息。
    • 我们如何通过 pss 凭据访问此图像?
    【解决方案3】:

    我不得不将入口点更改为空,以使其与以下脚本一起工作,它就像一个魅力:

    pipeline {
      agent {
        docker {
            image 'hashicorp/terraform:light'
            args '-i --entrypoint='
        }
      }
      stages {
        stage('Test') {
            steps {
                sh 'terraform --version'
            }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-18
      • 1970-01-01
      • 2017-12-20
      • 2019-05-30
      • 2021-03-12
      • 2015-06-18
      • 1970-01-01
      • 2021-12-01
      • 2018-04-29
      相关资源
      最近更新 更多