How to connect a docker piece to a container of dockers-denkins?

I have jenkins working inside a container and the github project source code.

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

My pipeline is as follows:

  • pull the source from github
  • create a project image
  • run project container

What I'm doing right now is using the host docker socket from the jenkins container:

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

I have a problem when the jenkins container mounts the source volume from / var / jenkins _home / workspace / BRANCH_NAME into the project container:

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

I get an empty folder "/ srv / app" in the project container

My best guess is that docker is trying to install it from the host, not from the jenkins container.

So the question is: how can I explicitly install the container from which I mount the volume?

+7
docker continuous-integration jenkins
source share
2 answers

to try:

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

where container identifier is the identifier of the container you want to get from mont data.

You can also create a volume using:

 docker volume create <volname> 

and assign it to both containers

 volumes: - <volname>:/srv/app 
+1
source share

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

My solution was to install docker inside the systemd container without sharing the toe.

 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.

+1
source share

All Articles