juliangut / docker-phpdev

PHP/PHP-FPM/Jenkins Docker image for development/CI, based on Alpine Linux for minimal size
https://hub.docker.com/r/juliangut/phpdev/
BSD 3-Clause "New" or "Revised" License
11 stars 2 forks source link

errors when running docker in Jenkins pipeline #26

Closed blacknell closed 2 years ago

blacknell commented 3 years ago

I've created a simple pipeline as follows and I can see in the log it pulling the container but it fails with errors as outlined below. Hoping you can provide some guidance and perhaps a README specific to gettings started with Jenkins is a next step.

pipeline {
    agent {
        docker {
            image 'juliangut/phpdev:jenkins-latest'
        }
    }
    stages {
        stage('Install') {
            steps {
                sh 'php -v'
                sh 'composer -V'

            }
        }
    }
}

Here is the error output (I have obfuscated the repository name to SSS/SSS).

Push event to branch main
11:53:33 Connecting to https://api.github.com using blacknell/******
Obtained Jenkinsfile from 2ca8389e3142b60e6e830dc466f7a610a577f9fe
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/u-there_SSS_main
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
using credential c19b3c6f-SSS
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/SSS/SSS.git # timeout=10
Fetching without tags
Fetching upstream changes from https://github.com/SSS/SSS.git
 > git --version # timeout=10
 > git --version # 'git version 2.20.4'
using GIT_ASKPASS to set credentials 
 > git fetch --no-tags --force --progress -- https://github.com/SSSS/SSS.git +refs/heads/main:refs/remotes/origin/main # timeout=10
Checking out Revision 2ca8389e3142b60e6e830dc466f7a610a577f9fe (main)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 2ca8389e3142b60e6e830dc466f7a610a577f9fe # timeout=10
Commit message: "Update Jenkinsfile"
 > git rev-list --no-walk 51b20ca213d9d04140ba460dcf5b2494741b1ba1 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] isUnix
[Pipeline] sh
+ docker inspect -f . juliangut/phpdev:jenkins-latest
.
[Pipeline] withDockerContainer
Jenkins seems to be running inside container c259aadf1dfdb7145fa9e202404a388e48e845ac0c95de427769a3251adc14b4
but /var/jenkins_home/workspace/u-there_SSS_main could not be found among []
but /var/jenkins_home/workspace/u-there_SSS_main@tmp could not be found among []
$ docker run -t -d -u 1000:1000 -w /var/jenkins_home/workspace/u-there_SSS_main -v /var/jenkins_home/workspace/u-there_SSS_main:/var/jenkins_home/workspace/u-there_SSS_main:rw,z -v /var/jenkins_home/workspace/u-there_SSS_main@tmp:/var/jenkins_home/workspace/u-there_SSS_main@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 ******** -e ******** -e ******** -e ******** juliangut/phpdev:jenkins-latest cat
$ docker top c88babf1ca4922521d4fa23709aaec90cb1e6671bcf3c7fadf0bf25a054e52bd -eo pid,comm
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

java.io.IOException: Failed to run top 'c88babf1ca4922521d4fa23709aaec90cb1e6671bcf3c7fadf0bf25a054e52bd'. Error: Error response from daemon: Container c88babf1ca4922521d4fa23709aaec90cb1e6671bcf3c7fadf0bf25a054e52bd is not running
    at org.jenkinsci.plugins.docker.workflow.client.DockerClient.listProcess(DockerClient.java:145)
    at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:199)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:286)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:126)
    at org.jenkinsci.plugins.docker.workflow.Docker.node(Docker.groovy:66)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(Docker.groovy:114)
    at org.jenkinsci.plugins.docker.workflow.declarative.DockerPipelineScript.runImage(DockerPipelineScript.groovy:57)
    at org.jenkinsci.plugins.docker.workflow.declarative.AbstractDockerPipelineScript.configureRegistry(AbstractDockerPipelineScript.groovy:73)
    at org.jenkinsci.plugins.docker.workflow.declarative.AbstractDockerPipelineScript.run(AbstractDockerPipelineScript.groovy:51)
    at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(CheckoutScript.groovy:61)
    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.GeneratedMethodAccessor262.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:129)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
    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:400)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
    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:131)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    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
blacknell commented 3 years ago

Incidentally, when I first created the pipeline with container image php:7.4-alpine, the php -v command executed fine (but of course composer failed)

juliangut commented 3 years ago

Hi @blacknell

Jenkins images are meant to be used as slave nodes, not as images on a pipeline. Try simply using juliangut/phpdev:latest and that should work