jenkins正在Docker容器中运行。
Docker正在Mac OS中使用。所以我在jenkins.yml中标出了这些行:
# mount docker sock and binary for docker in docker (only works on linux)
#- /var/run/docker.sock:/var/run/docker.sock
#- /usr/bin/docker:/usr/bin/docker
在Jenkinsfile中的是由JHipster生成的,包括管道中的两个任务:
列出项目
node {
stage('checkout') {
checkout scm
}
docker.image('openjdk:8').inside('-u root -e MAVEN_OPTS="-Duser.home=./"') {
stage('check java') {
sh "java -version"
}
来自bitbucket的结账成功了。管道停止并在docker“pull openjdk:8”时出错。控制台输出是:
[AAAAApp] Running shell script
+ docker inspect -f . openjdk:8
/var/jenkins_home/workspace/GeneticsDB@tmp/durable-21459aca/script.sh:
2: /var/jenkins_home/workspace/GeneticsDB@tmp/durable-21459aca/script.sh: docker: not found
[Pipeline] sh
[AAAAApp] Running shell script
+ docker pull openjdk:8
/var/jenkins_home/workspace/GeneticsDB@tmp/durable-d5590370/script.sh:
2: /var/jenkins_home/workspace/GeneticsDB@tmp/durable-d5590370/script.sh: docker: not found
但是这个命令可以在命令行中成功运行,如下所示:
docker pull openjdk:8
8: Pulling from library/openjdk
Digest: sha256:18c9622a8dc67b608a2dd0178b4c5aebc0e2da9a656072c6e799cfc46cb96422
Status: Image is up to date for openjdk:8
我知道有一个类似的问题:Docker not found when building docker image using Docker Jenkins container pipeline
但是我的docker在Mac OS上运行。
答案 0 :(得分:1)
问题实际上是如何在Docker for Mac上运行的容器中运行Docker。它由
修复brew install docker
并将jenkins.yml更新为
# mount docker sock and binary for docker in docker
- /var/run/docker.sock:/var/run/docker.sock
- /usr/local/bin/docker:/usr/local/bin/docker
答案 1 :(得分:0)
收到错误:
Warning: failed to get default registry endpoint from daemon (Got
permission denied while trying to connect to the Docker daemon socket
at unix:///var/run/docker.sock: Get
http://%2Fvar%2Frun%2Fdocker.sock/v1.35/info: dial unix
/var/run/docker.sock: connect: permission denied). Using system
default: https://index.docker.io/v1/
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Post
http://%2Fvar%2Frun%2Fdocker.sock/v1.35/images/create?
fromImage=openjdk&tag=8: dial unix /var/run/docker.sock: connect:
permission denied
解决方案:更新docker容器中/var/run/docker.sock的访问权限。
找到Jenkins的容器:docker container ps -a
登录容器:docker exec -it -u root ec379335d599 / bin / bash
upadte权限:chmod 777 /var/run/docker.sock
答案 2 :(得分:0)
如果您的jenkins在docker容器内运行,那么我建议:
我使用以root身份运行的入口点执行的最后一部分运行groupmod
来调整用户组的gid,然后使用exec
+ {{1}删除对该用户的权限用作为jenkins用户运行的jenkins服务器替换pid 1。执行此操作所需的所有代码都在以下git仓库中:https://github.com/sudo-bmitch/jenkins-docker