我刚尝试为Jenkins课程构建我的测试图像并得到了问题
+ docker build -t nginx_lamp_app .
/var/jenkins_home/jobs/docker-test/workspace@tmp/durable-d84b5e6a/script.sh: 2: /var/jenkins_home/jobs/docker-test/workspace@tmp/durable-d84b5e6a/script.sh: docker: not found
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
但是我已经在Jenkins的docker-compose文件中配置了docker socket,就像这样
version: "2"
services:
jenkins:
image: "jenkins/jenkins:lts"
ports:
- "8080:8080"
restart: "always"
volumes:
- "/var/jenkins_home:/var/jenkins_home"
- "/var/run/docker.sock:/var/run/docker.sock"
但是,当我附加到容器时,我也看到了#34;码头:未找到"当我输入命令" docker" ... 我已经更改了套接字777的权限 什么可能是错的?
谢谢!
答案 0 :(得分:0)
您正在尝试实现Docker-in-Docker类型的东西。仅安装docker socket不会使其按预期工作。您还需要在其中安装docker二进制文件。您可以通过扩展jenkins图像/ Dockerfile或在将docker二进制文件安装到其中后创建(docker commit
)新图像来实现此目的。将该图像用于CI / CD。尝试将下面的RUN
语句与扩展的Dockerfile或要提交的容器集成(应该在ubuntu docker镜像上工作) -
RUN apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce
参考 - https://github.com/jpetazzo/dind
PS - 不是真的推荐(http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/)
除此之外,你不应该在容器中安装主机docker二进制文件 -
⚠️这篇文章的旧版本建议绑定安装docker 从主机到容器的二进制文件。这不再可靠了, 因为Docker Engine不再像(几乎)静态分发 库。