![](/img/trans.png)
[英]Jenkins pipeline/docker :Jenkins does not seem to be running inside a container
[英]Jenkins Pipeline Docker -- Container is Not Running
我讓 Jenkins 在 EC2 實例上運行。 我在 Peered 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'
}
}
}
}
不工作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 問題; node:7-alpine
和hashicorp/terraform:light
什么hashicorp/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'
}
}
}
}
在腳本化管道中,您可以執行以下操作:
docker.image(dockerImage).inside("--entrypoint=''") {
// code to run on container
}
如果您正在從已經具有 ENTRYPOINT 指令的基礎鏡像創建要在 Jenkins 中使用的鏡像,您可以通過將這一行添加到您自己的 Dockerfile 的末尾來覆蓋它:
ENTRYPOINT []
那么整個 --entrypoint 就不再需要了。
我不得不將入口點更改為空以使其與以下腳本一起工作,它就像一個魅力:
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.