Docker in Docker in Jenkins Pipeline - how to access the Docker host?

95 views
Skip to first unread message

Damien Coraboeuf

unread,
Sep 26, 2016, 3:27:00 PM9/26/16
to Jenkins Users
Hi,

After having struggled, I decided to create a simplified version of a pipeline, which highlights the issue.

Environment: Linux, Jenkins 2.23, latest versions of the pipeline components.

Given the pipeline definition at https://github.com/nemerosa/jenkins-docker:
  1. I build a Docker image which allows to run Postgres PSQL client, Docker & Docker Compose
  2. I run it with '--volume=/var/run/docker.sock:/var/run/docker.sock' as arguments, to be able to run in the same Docker environment
  3. I run a serie a bash commands inside this container
  4. the first action I do is to create a Postgres container using Docker Compose
  5. I can get the port of the created Postgres container, no problem
  6. I then try to connect to the Postgres container - but which host can I use?
As mentioned, this is a simplification of a more complex case, but the general idea is a build which creates its own containers (like a database) and tries to connect to it to perform some tests. But this build runs itself in Docker container and does not seem able to reach the other containers on the specified port. I've tried localhost, ${NODE_NAME}. Nothing was worked so far.

The https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Custom+Build+Environment+Plugin is supposed to put DOCKER_HOST available for such a purpose, but this does not seem available any longer when in the pipeline.

Can someone help me resolve this problem?

Thanks,
Damien.

Damien Coraboeuf

unread,
Sep 27, 2016, 5:00:01 PM9/27/16
to Jenkins Users
I finally answered my own question and documented here: https://nemerosa.ghost.io/2016/09/27/docker-in-docker-in-jenkins-pipeline/

I hope it helps other people.

Best regards,
Damien.
Reply all
Reply to author
Forward
0 new messages