Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-30512

using ifconfig docker0 cannot get the IP address of the host for the docker command

    XMLWordPrintable

Details

    Description

      in https://github.com/jenkinsci/docker-custom-build-environment-plugin/blob/docker-custom-build-environment-1.6.0/src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java#L192, the getDocker0Ip method is using ifconfig docker0 but the result cannot be used in https://github.com/jenkinsci/docker-custom-build-environment-plugin/blob/docker-custom-build-environment-1.6.0/src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java#L164 for the docker command --add-host parameter.

      $ ifconfig docker0 
      invalid value "dockerhost:flags=4099<UP,BROADCAST,MULTICAST>" for flag --add-host: invalid IP address in add-host: "flags=4099<UP,BROADCAST,MULTICAST>" 
      See 'docker run --help'. 
      FATAL: Failed to run docker image 
      java.lang.RuntimeException: Failed to run docker image 
      at com.cloudbees.jenkins.plugins.docker_build_env.Docker.runDetached(Docker.java:186) 
      at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.startBuildContainer(DockerBuildWrapper.java:176) 
      at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerBuildWrapper.java:151) 
      at hudson.model.Build$BuildExecution.doRun(Build.java:154) 
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:536) 
      at hudson.model.Run.execute(Run.java:1741) 
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) 
      at hudson.model.ResourceController.execute(ResourceController.java:98) 
      at hudson.model.Executor.run(Executor.java:374) 
      Finished: FAILURE 
      

      Attachments

        Issue Links

          Activity

            I have this problem on CentOS 7.1. The output of ifconfig has changed:

            # ifconfig docker0
            docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
                    inet 10.3.0.1  netmask 255.255.255.0  broadcast 0.0.0.0
                    ether 02:42:26:cc:99:58  txqueuelen 0  (Ethernet)
                    RX packets 0  bytes 0 (0.0 B)
                    RX errors 0  dropped 0  overruns 0  frame 0
                    TX packets 0  bytes 0 (0.0 B)
                    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
            

            In CentOS 6.5 it works:

            $ ifconfig docker0
            docker0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00
                      inet addr:10.3.0.1  Bcast:0.0.0.0  Mask:255.255.255.0
                      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                      collisions:0 txqueuelen:0
                      RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
            
            daspilker Daniel Spilker added a comment - I have this problem on CentOS 7.1. The output of ifconfig has changed: # ifconfig docker0 docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 10.3.0.1 netmask 255.255.255.0 broadcast 0.0.0.0 ether 02:42:26:cc:99:58 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 In CentOS 6.5 it works: $ ifconfig docker0 docker0 Link encap:Ethernet HWaddr 00:00:00:00:00:00 inet addr:10.3.0.1 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
            daspilker Daniel Spilker added a comment - pull request: https://github.com/jenkinsci/docker-custom-build-environment-plugin/pull/30

            I had a similar problem on debian:jessie.

            The ifconfig command was not found, it only existed in /usr/sbin/. I fixed by symlinking /usr/sbin/ifconfig to /usr/bin/ifconfig. and adding the netdev group to the jenkins user.

            Is there a way to make this less system dependent ?

            msierks Michael Sierks added a comment - I had a similar problem on debian:jessie. The ifconfig command was not found, it only existed in /usr/sbin/. I fixed by symlinking /usr/sbin/ifconfig to /usr/bin/ifconfig. and adding the netdev group to the jenkins user. Is there a way to make this less system dependent ?

            Ah, right. Something like this should do:

            java.net.NetworkInterface docker0 = java.net.NetworkInterface.getByName('docker0');
            String ip = docker0.getInterfaceAddresses().get(0).getAddress().getHostAddress();
            
            daspilker Daniel Spilker added a comment - Ah, right. Something like this should do: java.net.NetworkInterface docker0 = java.net.NetworkInterface.getByName( 'docker0' ); String ip = docker0.getInterfaceAddresses().get(0).getAddress().getHostAddress();

            Following daspilker idea, I wrote a fix using native Java API in PR-32

            ydubreuil Yoann Dubreuil added a comment - Following daspilker idea, I wrote a fix using native Java API in PR-32

            Code changed in jenkins
            User: Yoann Dubreuil
            Path:
            src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java
            http://jenkins-ci.org/commit/docker-custom-build-environment-plugin/7b9b8a689eb7ec9036bdea322b56d125e1102a07
            Log:
            JENKINS-30512 use java API instead of ifconfig to lookup docker0 ipv4 address

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Yoann Dubreuil Path: src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java http://jenkins-ci.org/commit/docker-custom-build-environment-plugin/7b9b8a689eb7ec9036bdea322b56d125e1102a07 Log: JENKINS-30512 use java API instead of ifconfig to lookup docker0 ipv4 address

            Code changed in jenkins
            User: Nicolas De loof
            Path:
            src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java
            http://jenkins-ci.org/commit/docker-custom-build-environment-plugin/098a4b8d54d41ae933382668d1e36fd485bdef55
            Log:
            Merge pull request #32 from ydubreuil/fix-JENKINS-30512

            JENKINS-30512 use java API instead of ifconfig to lookup docker0 ipv4 address

            Compare: https://github.com/jenkinsci/docker-custom-build-environment-plugin/compare/e8dd7e46a648...098a4b8d54d4

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Nicolas De loof Path: src/main/java/com/cloudbees/jenkins/plugins/docker_build_env/Docker.java http://jenkins-ci.org/commit/docker-custom-build-environment-plugin/098a4b8d54d41ae933382668d1e36fd485bdef55 Log: Merge pull request #32 from ydubreuil/fix- JENKINS-30512 JENKINS-30512 use java API instead of ifconfig to lookup docker0 ipv4 address Compare: https://github.com/jenkinsci/docker-custom-build-environment-plugin/compare/e8dd7e46a648...098a4b8d54d4

            Fixed released in 1.6.1

            ydubreuil Yoann Dubreuil added a comment - Fixed released in 1.6.1

            People

              ydubreuil Yoann Dubreuil
              alecharp Adrien Lecharpentier
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: