Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

374
Visualizações
How to mount docker volume with jenkins docker container?

I have jenkins running inside container and project source code on github.

I need to run project in container on the same host as jenkins, but not as docker-in-docker, i want to run them as sibling containers.

My pipeline looks like this:

  1. pull the source from github
  2. build the project image
  3. run the project container

What i do right now is using the docker socket of host from jenkins container:

/var/run/docker.sock:/var/run/docker.sock

I have problem when jenkins container mount the volume with source code from /var/jenkins_home/workspace/BRANCH_NAME to project container:

volumes:
 - ./servers/identity/app:/srv/app

i am getting empty folder "/srv/app" in project container

My best guess is that docker tries to mount it from host and not from the jenkins container.

So the question is: how can i explicitly set the container from which i mount the volume?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

I got the same issue when using Jenkins docker container to run another container.

Senario 1 - Running container inside Jenkins docker container

This is not a recommended way, explanations goes here. If you still need to use this approach, then this problem is not a problem.

Senario 2 - Running docker client inside Jenkins container

Suppose, we need to run another container (ContainerA) inside Jenkins docker container, docker pipeline plugin will use --volumes-from to mount Jenkins container volume to ContainerA.

If you trying to use --volume or -v to map specific directory in Jenkins container to ContainerA, you will got an unexpected behavior.

That's because --volumes or -v would try to map directories in host to ContainerA, rather than mapping from directories inside Jenkins container. If the directories not found in host, then you will get an empty dir inside ContainerA.

In short, we can not map a specific directory from containerA to containerB, we could only mount the whole volumes from containerA to containerB, and volume alias is not supported.

Solution

  1. If your Jenkins is running with host volume, you can map the host directories to the target container.
  2. Otherwise, you can access the files inside the newly created container with the same location as Jenkins container.
over 4 years ago · Santiago Trujillo Relatório

0

try:

docker run -d --volumes-from <ContainerID> <YourImage>

where container ID is id of container you want for mont data from.

You can also create volume, by:

docker volume create <volname>

and assign it to both containers

volumes:
 - <volname>:/srv/app
over 4 years ago · Santiago Trujillo Relatório

0

Sharing the sock between the Host and Jenkins was my problem because "/var/jenkins_home" is most likely a volume for the Jenkins container.

My solution was installing docker inside a systemd container without sharing the sock.

docker run -d --name jenkins \
    --restart=unless-stopped \
    --privileged \
    -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
    -v jenkins-vol:/var/lib/jenkins \
    --tmpfs /run \
    --tmpfs /run/lock \
    ubuntu:16.04 /sbin/init

Then install Jenkins, Docker and Docker Compose on it.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda