Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline/docker :Jenkins does not seem to be running inside a container

I'm trying to execute the sample of code found in Jenkins Pipeline here : https://jenkins.io/doc/book/pipeline/docker/

node {
/* Requires the Docker Pipeline plugin to be installed */
    docker.image('maven:3-alpine').inside('-v $HOME/.m2:/root/.m2') {
        stage('Build') {
            sh 'mvn -B'
        }
    }
}

And give me this error:

[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container 
[Pipeline] // withDockerContainer

I don't know why is it stopping like that without doing anything.

I have already install docker, docker plugin/docker pipeline on the latest version.

In configuration tool, i add the installation root path.

Did I miss something ? Thanks in advance

like image 629
flopic Avatar asked Oct 12 '17 14:10

flopic


1 Answers

The issue is a bit old but I faced a similar situation and I want to share.

I noticed that Jenkins mentions the the cause of the issue at the end of the pipeline logs.

For example in my case, the issue states:

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

When checking the stage where this happened it's similar to the above you mentioned when using dockerImage.inside(), the reason in my case is that my Dockefile already defines an entrypoint and when using the inside feature jenkins gets confused, so to avoid this try overriding the entrypoint by passing it as a parameter to the inside function as follows:

dockerImage.inside("--entrypoint=''") {
     echo "Tests passed"
}

Another good way to find the issue is to access your jenkins server ans list the docker containers with docker ps -a you may find the build container failed, check the logs then you will get a hint, in my case the logs says cat: 1: ./entrypoint.sh: not found.

like image 118
Sadmi Avatar answered Oct 06 '22 00:10

Sadmi