Docker 容器里运行Docker
参考文章:https://www.cnblogs.com/netflix/p/15131498.html
背景
部署了Jenkins容器后,需要再Jenkins里运行docker bulid 镜像等命令,这个时候就会用到
步骤
在Jenkins容器里运行docker
需要加上挂载宿主机的目录
-v /var/run/docker.sock:/var/run/docker.sock
-v /usr/bin/docker:/usr/bin/docker
运行jenkins的命令
docker run --name my_jenkins -p 8080:8080 -p 50000:50000 -d --env JAVA_OPTS=-Duser.timezone=Asia/Shanghai -v /usr/local/my_jenkins/:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker --privileged=true --restart=always jenkins/jenkins
在Jenkins构建时坑点
- 错误信息
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Delete "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/my_fast_vue?force=1": dial unix /var/run/docker.sock: connect: permission denied Build step 'Execute shell' marked build as failure Finished: FAILURE
解决方式
chmod 777 /var/run/docker.sock
--粗暴一点,直接给与所有权限
本文来自博客园,作者:弩哥++,转载请注明原文链接:https://www.cnblogs.com/bangbangzoutianya/p/16734000.html