Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add software or other packages to a docker container?

I have pulled jenkins container from docker hub like this:

docker pull jenkins

The container runs and I can access Jenkins UI in :

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?

It appears that the docker container does not share any reference with local host file system.

How can I install such packages in this running container?

Thanks

like image 314
Becks Avatar asked Jul 19 '17 05:07

Becks


1 Answers

You will need to install all your dependencies at docker container build time.

You can make your own Dockerfile off of the jenkins library, and then put custom stuff in there. Your Dockerfile can look like

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.

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. Given that its an external link, here's the relevant dockerfile from there,

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.

like image 107
Debosmit Ray Avatar answered Sep 19 '22 10:09

Debosmit Ray