詹金斯在Docker容器中(运行Docker管道)
我想在Docker容器中运行Jenkins.一切都好.我可以这样运行:docker run -d --name jenkins -t -i -p 49001:8080 jenkins
我也可以添加持久性存储.当我创建管道可以执行docker
命令(build
和push
)时,问题就来了.首先,错误是未在系统上安装docker.是的,期望.然后我开始搜索,发现如何在容器中运行docker(传递2个持久卷):docker run ... -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -p 49001:8080 jenkins
I want to run Jenkins in Docker container. Everything is OK. I can run it like this: docker run -d --name jenkins -t -i -p 49001:8080 jenkins
I can also add persistent storage. The problem came when I created a pipeline can has to execute docker
commands (build
and push
). First the error was that docker wasn't installed on the system. Yes, expected. Then I started searching and found out how I can run docker in container (passing 2 persistent volumes): docker run ... -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -p 49001:8080 jenkins
这会运行,但是有一些例外.容器中有docker
命令,但是当我尝试运行它时,它会引发异常:docker: error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory
This runs, but with some exceptions. There is docker
command in the container but when I try to run it, it throws an exception: docker: error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory
如何解决此问题?在Docker中安装Jenkins并在其中运行Docker的正确方法是什么?我认为有两种方法:
How can I fix this problem? What is the correct way for installing Jenkins in Docker and run Docker in it? I think there are 2 ways:
- 我正在做的-使用套接字
- 我可以公开允许连接和运行命令的docker api
实际上值得在Docker中运行Jenkins吗?我试图从apt-get
手动安装缺少的lib,它可以工作,但我知道这不是正确的方法.
Actually is it worth running Jenkins in Docker? I tried to install the missing lib manually from the apt-get
It works but I know that it's not the correct way..
您必须安装libltdl-dev
才能正常运行.创建一个如下所示的Dockerfile
:
You have to install libltdl-dev
in order to get everything working correctly. Create a Dockerfile
that looks like this:
FROM jenkins:latest
USER root
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y sudo libltdl-dev \
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
USER jenkins
# Here you can install some Jenkins plugins if you want