简体   繁体   English

Jenkins Pipeline Docker -- 容器未运行

[英]Jenkins Pipeline Docker -- Container is Not Running

I have Jenkins running on an EC2 Instance.我让 Jenkins 在 EC2 实例上运行。 I have the EC2 Plugin Configured in a Peered VPC, and when a job is tagged 'support_ubuntu_docker' it will spin up an Jenkins Slave, with Docker pre-installed.我在 Peered VPC 中配置了 EC2 插件,当作业被标记为“support_ubuntu_docker”时,它将启动一个 Jenkins Slave,并预装了 Docker。

I am able to follow the examples, and get my job to connect to the local docker running on the Slave, and run commands inside the container.我能够按照示例进行操作,并将我的工作连接到在 Slave 上运行的本地 docker,并在容器内运行命令。

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

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

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

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

I have tried with the ansible/ansible:default image, as well as a image I created myself.我尝试过 ansible/ansible:default 图像,以及我自己创建的图像。

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

This image behaves locally.此图像在本地运行。

[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]
/ # 

I really just want to be able to clone my terraform git repo, and use the terraform in the container to run my init/plan/applies.我真的只想能够克隆我的 terraform git repo,并使用容器中的 terraform 来运行我的 init/plan/applies。

The error im getting for all of these is.我对所有这些的错误是。

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

The question really should have been a Docker question;这个问题真的应该是一个 Docker 问题; what's the difference between node:7-alpine and hashicorp/terraform:light ? node:7-alpinehashicorp/terraform:light什么hashicorp/terraform:light

hashicorp/terraform:light has an ENTRYPOINT entry, pointing to /bin/terraform . hashicorp/terraform:light有一个ENTRYPOINT条目,指向/bin/terraform
Basically that means you run it this way:基本上这意味着您以这种方式运行它:
docker run hashicorp/terraform:light --version
And it will exit right away, ie, it's not interactive.它会立即退出,即它不是交互式的。
So if you want an interactive shell within that Docker container, you'll have to override the ENTRYPOINT to point at a shell, say, /bin/bash and also tell Docker to run interactively:因此,如果您想要该 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'
            }
        }
    }
}

In a scripted pipeline you can do this:在脚本化管道中,您可以执行以下操作:

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

If you are creating the image to use in Jenkins from a base image that already has an ENTRYPOINT instruction, you can override it by adding this line to the end of your own Dockerfile:如果您正在从已经具有 ENTRYPOINT 指令的基础镜像创建要在 Jenkins 中使用的镜像,您可以通过将这一行添加到您自己的 Dockerfile 的末尾来覆盖它:

ENTRYPOINT []

Then the whole --entrypoint is no longer needed.那么整个 --entrypoint 就不再需要了。

I had to change the entrypoint to empty to get it working with the following script it worked like a charm:我不得不将入口点更改为空以使其与以下脚本一起工作,它就像一个魅力:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 詹金斯管道/码头:詹金斯似乎没有在容器内运行 - Jenkins pipeline/docker :Jenkins does not seem to be running inside a container 在 Docker 容器中从 Jenkins 管道运行 Django 服务器 - Running Django server from Jenkins pipeline in Docker container 从 Jenkins 管道运行 Docker 容器,并捕获 output - Running a Docker container from a Jenkins pipeline, and capture the output 从Jenkins管道调用Docker容器,该管道在Windows上也作为Docker容器在Docker上运行(对于Windows 10) - Invoke docker container from Jenkins pipeline which is also running as docker container on Windows for docker (for Windows 10) 在Docker容器中运行Jenkins - Running Jenkins in a Docker Container 使用 Jenkins 管道在 Jenkins 上构建 docker 容器 - Building a docker container on Jenkins using a Jenkins Pipeline 在Jenkins(在docker容器中)管道中构建docker镜像 - Build docker image in Jenkins (in docker container) pipeline Jenkins 管道:在 docker 容器内构建 docker - Jenkins Pipeline: Build docker within docker container Docker 容器中的 Jenkins(运行 docker 管道) - Jenkins in Docker container (run docker pipeline) Docker管道的“内部”在运行于Docker容器中的Jenkins从站中不起作用 - Docker pipeline's “inside” not working in Jenkins slave running within Docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM