简体   繁体   English

如何将软件或其他软件包添加到docker容器中?

[英]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.

相关问题 docker container jupyter lab,如何添加其他包? - docker container jupyter lab, how to add other packages? 如何使用 pipenv 将包添加到现有的 docker 容器 - How do I add packages to an existing docker container using pipenv 我如何在正在运行的 docker 容器中安装包并且包在不重新创建容器的情况下生效? - how I can install packages inside a running docker container and packages take effect without recreating the container? Python和Docker:如何将软件包添加到sys.path中? - Python & docker: how can i add packages into sys.path? 如何访问同一 Docker 容器中的其他文件? - How can I access other files in the same Docker container? 我应该如何处理软件包? - How should I handle software packages? 如何将 tesseract 添加到我的 Docker 容器中,以便我可以使用 pytesseract - How do I add tesseract to my Docker container so i can use pytesseract 如何在 VScode 中添加 python 包? - How can i add python packages in VScode? 设置 docker 容器,以便我可以访问 ubuntu 服务器上的 python 包 - Setting up docker container so that I can access python packages on ubuntu server 如何将两个 Docker 容器链接在一起? 一个是MySQL容器托管数据库,另一个是Python flask应用 - How can I link two Docker containers together? One is a MySQL container hosting the database, and the other is a Python flask application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM