Jenkins管道Docker-容器未运行

Jus*_*ser 3 amazon-ec2 jenkins docker

我让Jenkins在EC2实例上运行。我在对等VPC中配置了EC2插件,当作业标记为“ support_ubuntu_docker”时,它将启动Jenkins Slave,并预安装了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'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

不起作用https://pastebin.com/MsSZaPha

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

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

FROM alpine:3.7
RUN apk add --no-cache terraform
RUN apk add --no-cache ansible
ENTRYPOINT ["/bin/ash"]
Run Code Online (Sandbox Code Playgroud)

此图像在本地运行。

[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]
/ # 
Run Code Online (Sandbox Code Playgroud)

我真的只是想能够克隆我的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
Run Code Online (Sandbox Code Playgroud)

S.S*_*ker 8

我必须将入口点更改为空才能使其与以下脚本一起工作,它的工作方式就像一个魅力:

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


Lee*_*dor 6

在脚本化管道中,您可以执行以下操作:

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

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

ENTRYPOINT []
Run Code Online (Sandbox Code Playgroud)

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


小智 5

这个问题确实应该是Docker问题;node:7-alpine和之间有什么区别hashicorp/terraform:light

hashicorp/terraform:light有一个ENTRYPOINT条目,指向/bin/terraform
基本上,这意味着您
docker run hashicorp/terraform:light --version
将以这种方式运行:并且它将立即退出,即,它不是交互式的。
因此,如果您想在该Docker容器中使用交互式外壳,则必须重写,ENTRYPOINT以指向外壳,例如,/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'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 我对此表示赞成,因为它解决了问题的根源,但这对我不起作用,而 S.Spiker 的答案有效。 (5认同)