简体   繁体   中英

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 he stoping like that without doing anything.

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

In configuration tool, i add the installation root path.

Did I miss something ? Thanks in advance

This message is a normal debug message, maybe a little confusing, but not an error. As the Jenkins Pipeline code is written, during initialization it checks whether the step is already running in a container. I think the message could be written better.

If you have more problems than this message, please provide the entire log. Sounds like maybe a node cannot be assigned, or the docker client is not installed, or the docker image cannot be pulled.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM