Jenkins + Docker:守护进程的错误响应:容器未运行

Jenkins + Docker:守护进程的错误响应:容器未运行

我目前正在尝试我的第一个 Jenkins 项目。如果 Github 上有提交,则应该简单地创建并发布 Docker 映像。我正在使用安装了 Jenkins 和 Docker 的 EC2 实例。

不幸的是,每当我尝试在 Jenkins 中构建时,在测试阶段都会出现错误。以下是日志:

[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/Jenkins-Project
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Clone repository)
[Pipeline] checkout
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
No credentials specified
 > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/Jenkins-Project/.git # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/Momo979/JenkinsTest.git # timeout=10
Fetching upstream changes from https://github.com/Momo979/JenkinsTest.git
 > git --version # timeout=10
 > git --version # 'git version 2.32.0'
 > git fetch --tags --force --progress -- https://github.com/Momo979/JenkinsTest.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision d0bdbc09d8ffbb83306c1121adfacae6ccd4619c (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f d0bdbc09d8ffbb83306c1121adfacae6ccd4619c # timeout=10
Commit message: "Added Jenkins File"
 > git rev-list --no-walk d0bdbc09d8ffbb83306c1121adfacae6ccd4619c # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build image)
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker build -t momo979/purple-beard-team-2 .
Sending build context to Docker daemon  96.77kB

Step 1/7 : FROM ubuntu:18.04
 ---> dcf4d4bef137
Step 2/7 : RUN apt-get update -y &&  apt-get install apache2 curl -y --no-install-recommends
 ---> Using cache
 ---> dd58d308db53
Step 3/7 : WORKDIR /var/www/html/
 ---> Using cache
 ---> 45b0caaa0bdb
Step 4/7 : COPY index.html .
 ---> Using cache
 ---> 5b883f6013e6
Step 5/7 : HEALTHCHECK CMD curl -f http://localhost/ || exit 1
 ---> Using cache
 ---> 488aa2c526a1
Step 6/7 : EXPOSE 80
 ---> Using cache
 ---> 4ebb1d368fde
Step 7/7 : ENTRYPOINT [ "apache2ctl", "-D", "FOREGROUND" ]
 ---> Using cache
 ---> 764571e46e46
Successfully built 764571e46e46
Successfully tagged momo979/purple-beard-team-2:latest
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Test image)
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
+ docker inspect -f . momo979/purple-beard-team-2
.
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 995:993 -w /var/lib/jenkins/workspace/Jenkins-Project -v /var/lib/jenkins/workspace/Jenkins-Project:/var/lib/jenkins/workspace/Jenkins-Project:rw,z -v /var/lib/jenkins/workspace/Jenkins-Project@tmp:/var/lib/jenkins/workspace/Jenkins-Project@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** momo979/purple-beard-team-2 cat
$ docker top 3cad99c25fab50292e044245cea0f082016e2285c9576e75c2c565be1e295736 -eo pid,comm
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: Failed to run top '3cad99c25fab50292e044245cea0f082016e2285c9576e75c2c565be1e295736'. Error: Error response from daemon: Container 3cad99c25fab50292e044245cea0f082016e2285c9576e75c2c565be1e295736 is not running
    at org.jenkinsci.plugins.docker.workflow.client.DockerClient.listProcess(DockerClient.java:152)
    at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:200)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:319)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:193)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:140)
    at org.jenkinsci.plugins.docker.workflow.Docker.node(Docker.groovy:66)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:125)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy)
    at WorkflowScript.run(WorkflowScript:18)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
    at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:402)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:314)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:278)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

Dockerfile

FROM ubuntu:18.04
RUN apt-get update -y && \
 apt-get install apache2 curl -y --no-install-recommends
WORKDIR /var/www/html/
COPY index.html .
HEALTHCHECK CMD curl -f http://localhost/ || exit 1
EXPOSE 80
ENTRYPOINT [ "apache2ctl", "-D", "FOREGROUND" ]

Jenkins文件

node {
    def app

    stage('Clone repository') {
      

        checkout scm
    }

    stage('Build image') {
  
       app = docker.build("momo979/purple-beard-team-2")
    }

    stage('Test image') {
  

        app.inside {
            sh 'echo "Tests passed"'
        }
    }

    stage('Push image') {
        
        docker.withRegistry('https://registry.hub.docker.com', 'Dockerhub') {
            app.push("${env.BUILD_NUMBER}")
            app.push("latest")
        }
    }
}

该图像创建一个静态 HTML 页面。

感谢您的帮助!

相关内容