[英]How can I add software or other packages to a docker container?
I have pulled jenkins container from docker hub like this: 我从这个码头集线器中拉出了jenkins容器:
docker pull jenkins
The container runs and I can access Jenkins UI in : 容器运行,我可以访问Jenkins UI:
http://localhost:8080
My question is: 我的问题是:
If I want to be able to create a jenkins job that pulls from a github repo and I want to run some python tests from one of the test files of that repo, how can I install extra packages such as virtualenvwrapper, pip, pytest, nose, selenium
etc? 如果我想能够创建一个从github repo中获取的jenkins作业,并且我想从该repo的一个测试文件中运行一些python测试,我该如何安装额外的软件包,如
virtualenvwrapper, pip, pytest, nose, selenium
等?
It appears that the docker container does not share any reference with local host file system. 似乎docker容器不与本地主机文件系统共享任何引用。
How can I install such packages in this running container? 如何在此运行容器中安装此类软件包?
Thanks 谢谢
You will need to install all your dependencies at docker container build time. 您需要在docker container build time安装所有依赖项。
You can make your own Dockerfile
off of the jenkins library, and then put custom stuff in there. 你可以让你自己
Dockerfile
关闭詹金斯库,然后把自定义的东西在里面。 Your Dockerfile
can look like 你的
Dockerfile
看起来像
FROM jenkins:latest
MAINTAINER Becks
RUN apt-get update && apt-get install -y {space delimited list of package}
Then, you can do something like... 然后,你可以做点什么......
docker build -t jenkins-docker --file Dockerfile .
docker run -it -d --name=jenkins-docker jenkins-docker
I might not have written all the syntax correctly, but this is basically what you need to do. 我可能没有正确编写所有语法,但这基本上是你需要做的。 If you want the
run
step to spin up jenkins, follow along with what they are doing in the existing Dockerfile
here and add relevant sections to your dockerfile, to add some RUN
steps to run jenkins. 如果你想要
run
步骤来启动jenkins,请在这里跟随它们在现有Dockerfile
中所做的事情,并将相关部分添加到dockerfile,添加一些RUN
步骤来运行jenkins。
Came across this page , which approaches a similar problem, although it also mounts the docker sock inside another container, to kind of connect one container to another. 遇到了这个类似问题的页面 ,虽然它也将docker sock安装在另一个容器中,将一个容器连接到另一个容器。 Given that its an external link, here's the relevant dockerfile from there,
鉴于它是一个外部链接,这里是相关的dockerfile,
FROM jenkins:1.596
USER root
RUN apt-get update \
&& apt-get install -y sudo \
&& rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
USER jenkins
COPY plugins.txt /usr/share/jenkins/plugins.txt
RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
And this is how you can spin it up. 这就是你如何把它搞砸了。
docker build -t myjenk .
...
Successfully built 471fc0d22bff
$ docker run -d -v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker -p 8080:8080 myjenk
I strongly suggest going through that post. 我强烈建议你阅读这篇文章。 Its pretty awesome.
它非常棒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.