andymel
andymel

Reputation: 5736

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?

Upvotes: 2

Views: 4080

Answers (1)

andymel
andymel

Reputation: 5736

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:

  • I create a docker network "Jenkins_network"
  • I connect the jenkins container to that network
  • I connect the npm-registry container to that network

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 {
  ...

Upvotes: 6

Related Questions