jenkins-pipelinedocker-in-dockerverdaccio

Docker in Docker - Jenkins Docker Pipeline - how to connect to outside Service


I have the following setup

The problem is, as the registry runs on a port on the host it can't be reached from the docker in docker container that the Build Script spawns to build the lib. I find no info about how I can do something like --net="host" (from docker run) inside the jenkinsfile. I guess that would work?!

Any idea how I can improve the setup to build via a node docker container but be able to publish to the registry?


Solution

  • I fixed it by connecting all three containers (jenkins, npm-registry and the container spawned for the build) to the same custom docker network.

    As I configure the whole Jenkins server with Ansible I added following to the ansible script:

    In the jenkinsfile I added args '--net="jenkins_network"' to the docker block, which is now

    pipeline {
      agent {
          docker {
              image 'node:lts-alpine'
              args  '--net="jenkins_network"'
          }
      }
      stages {
      ...