简体   繁体   English

詹金斯管道/码头:詹金斯似乎没有在容器内运行

[英]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/我正在尝试执行在 Jenkins Pipeline 中找到的代码示例: 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.我已经在最新版本上安装了 docker、docker plugin/docker pipeline。

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. 在编写Jenkins管道代码时,在初始化期间它会检查该步骤是否已在容器中运行。 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. 听起来可能无法分配节点,或者未安装docker客户端,或者无法提取docker镜像。

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.我注意到 Jenkins 在管道日志的末尾提到了问题的原因。

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()时提到的上述情况,在我的情况下,原因是我的 Dockefile 已经定义了一个entrypoint点,并且在使用inside功能时 jenkins 会感到困惑,所以要避免这种尝试通过将入口点作为参数传递给inside函数来覆盖entrypoint ,如下所示:

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 .找到问题的另一个好方法是访问您的 jenkins 服务器并使用 docker docker ps -a列出 docker 容器,您可能会发现构建容器失败,检查日志然后您会得到提示,在我的情况下,日志显示cat: 1: ./entrypoint.sh: not found

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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