Docker: Cannot install inside docker container

Created on 11 Sep 2016  路  8Comments  路  Source: jenkinsci/docker

I have a jenkins (docker) image running and everything was fine. A few days ago I created a job so I can run my nodejs tests every time a pull request is made. one of the job's build steps is to run npm install. And the job is constantly failing with this error:

tar (child): bzip2: Cannot exec: No such file or directory

So, I know that I have to install bzip2 inside the jenkins container, but how do I do that? I've already tried to run docker run jenkins bash -c "sudo apt-get bzip2" but I got: bash: sudo: command not found.

With that said, how can I do that?

Thanks i advance

question

Most helpful comment

@lfcgomes @ndeloof

docker exec -u 0 -it mycontainer bash

All 8 comments

  1. you should not run build inside this image, but attach some slave containers, or use a jenkins plugin to run build slave containers on demand
  2. to customize image, write a Dockerfile to extend this image with custom tools.

@ndeloof I'm going to explain in detail. I need to install bzip2 in jenkins container. But I do not have permissions to run apt-get install command.

I cannot customize an image to extend the existing one because that way I'd loose all the jobs and configs that I have, right? And I have a lot of them... How can I solve this? What can I do to install bzip2 inside a jenkins container so it can be used my jobs?

Or, how can I perform the point 1 you wrote?

to install additional tools, create a Dockerfile:

FROM jenkins
USER root
CMD apt-get install xxxx
USER jenkins

build and use resulting image to run your customized jenkins master image

About point 1, if you want a fixed set of jenkins agent use https://github.com/jenkinsci/docker-jnlp-slave docker image to connect an agent container to your jenkins master. Other option if you rely on docker-plugin to create agents on demand is to bind mount /var/run/docker.sock in your container so it can interact with underlying docker host and start sidecar containers.

@ndeloof But if I create the dockerfile, I'll loose everything that I have in my current jenkins container, right?

jenkins_home is set as a volume, it's not inside container (data should never be stored in container). Use docker inspect to determine the volume being used. Would better have first ran docker run -v jenkins_home:/var/jenkins_home jenkins so this volume has a logical name.

@lfcgomes @ndeloof

docker exec -u 0 -it mycontainer bash

@EdisonSu768 running container as root definitively is an anti-pattern. Just understand how to manage docker volumes, not considering them as host folders, and you'll get this to run fine

Was this page helpful?
0 / 5 - 0 ratings