0

On my Jenkins server (deployed with the official jenkins image), I need to run the following code to build my docker image

def buildDockerImage() {
  sh "docker build --network=host -t $DOCKER_REPO ."
}

Note the --network=host option.

Now my problem is that on my development laptop, I don't need that option to build my image. Why is that? Why don't I need that on my laptop but I need it on the jenkins server? The Jenkins server is hosted on a Jelastic environment, like this:

env:
    topology:
        nodes:
          - image: jenkins/jenkins:lts
            count: 1
            cloudlets: 32
            nodeGroup: cp

Docker is installed like this:

mv /etc/init.d/kmod /etc/init.d/kmod.back
apt -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt update
apt -y install docker-ce docker-ce-cli containerd.io
service docker start
usermod -aG docker jenkins

Is there something I need to configure to make it happen without that network option?

Laurent Michel
  • 1,069
  • 3
  • 14
  • 29
  • why do you think that you need it ? – LinPy Oct 29 '19 at 07:59
  • because otherwise I get build errors because of lacking internet connection; if I, however, put the option there, the internet connection is made and e.g. ubuntu packages can be downloaded during the build of my image – Laurent Michel Oct 29 '19 at 08:02

2 Answers2

2

The misunderstanding locates at that place where Jenkins has been preinstalled and the Docker tool installed after. The Jelastic provides using the variables and special redirection. By default, Jenkins is redirected from port 80 to 8080 and you can reach it directly through already generated environment name. The way you should follow is disabling autoredirection by special 'JELASTIC_EXPOSE=DISABLED' variable and use public IP. In case you don't like to use public IP, find endpoint feature.

Everything about this is described in ports article

Virtuozzo
  • 1,993
  • 1
  • 10
  • 13
1

Based on Jelastic's answer, I added the following step to the jps manifest installing my Jenkins CI/CD environment:

actions:
    setupJenkinsForDocker:
      - api:
          - method: jelastic.environment.control.AddContainerEnvVars
            params:
              nodeGroup: cp
              vars:
                JELASTIC_EXPOSE: DISABLED
      - api:
          - method: jelastic.environment.control.AddEndpoint
            params:
              nodeId: ${nodes.cp.id}
              privatePort: 8080
              protocol: TCP 
              name: jenkins/jenkins

Of course, that implied that I adapt all my webhooks which trigger some jobs on that jenkins environment, because this is requiring a port in my jenkins endpoint.

Now, I don't need to set option --network=host anymore when I build a docker image requiring internet connection.

Laurent Michel
  • 1,069
  • 3
  • 14
  • 29