Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins not able to access internet when running as docker container

I am running the jenkins docker image. When starting, it complains that it is not possible to access the internet.

This is how I run it:

docker pull jenkins
mkdir jenkins-shared-volume
docker run -d -p 49001:8080 -p 50000:50000 -v jenkins-shared-volume:/var/jenkins_home -t --name jenkins jenkins

The jenkins instance is then running on http://localhost:49001. But it has connectivity issues:

Offline This Jenkins instance appears to be offline.

For information about installing Jenkins without an internet connection, see the Offline Jenkins Installation Documentation.

You may choose to continue by configuring a proxy or skipping plugin installation.

enter image description here

I have no proxy in my system (home laptop). I guess this is probably an obscure docker problem but:

  1. I can not find any references to this issue
  2. Since this is the usual way in which people would be running the jenkins docker image, I find it surprising that this is not working out of the box

Am I doing something wrong?

EDIT

Just to make sure that indeed the docker container has direct access to the internet:

docker exec -it jenkins /bin/bash
jenkins@4ef4944a7cb7:/$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=44 time=29.859 ms

EDIT2

Running the container connected to the host network solves the problem and lets jenkins access the internet:

docker run -d --net host -v jenkins-shared-volume:/var/jenkins_home -t --name jenkins jenkins

But I can not map ports: jenkins is directly reachable on http://localhost:8080, which can be a source of conflicts whenever other services are using the 8080 port.

like image 599
blueFast Avatar asked Sep 21 '16 05:09

blueFast


People also ask

How do I allow Jenkins user to run Docker?

Compose Configuration (Linux or macOS) Add a group docker if it does not exist, and add jenkins user to the docker group, e.g. groupadd docker && usermode -aG docker 'jenkins' . Adjust permissions on the docker. sock file so that jenkins user can access it, e.g. chmod 777 /var/run/docker.

Can Jenkins run Docker container?

Docker's fundamental platform and container design means that a single Docker image (for any given application like Jenkins) can be run on any supported operating system (macOS, Linux and Windows) or cloud service (AWS and Azure) which is also running Docker.

How does Jenkins Pipeline integrate with Docker?

Go to Manage Jenkins -> Plugins -> Available and type “docker” into the field. Select “Docker plugin” and install it. Jenkins refers to the Docker plugin as a “cloud.” Click Manage Jenkins once again, and now click the Manage Clouds and Nodes button in the middle. Now click Configure Clouds on the left.

How can I access Jenkins container from browser?

To see Jenkins, simply bring up a web browser and go to URL http :// myServer :8080 where myServer is the name of the system running Jenkins.


2 Answers

Strangely I ran into the same issue last night using the official Jenkins image:

 docker run -p 8080:8080 --rm jenkins/jenkins

Though I have not figured out why yet or how to permanently fix it, I did find a work around.

Launch the image with the older un-supported image jenkins... do the initial setup.. then shut it down, swap the image and startup the official.

For reference here is my docker-compose.yml:

version: "2"

services:
  app:
    image: jenkins #after booting and initial setup swap to jenkins/jenkins
    ports:
      - "50000:50000"
      - "8080:8080"
    volumes:
      - home:/var/jenkins_home
volumes:
  home:
like image 106
voglster Avatar answered Sep 18 '22 01:09

voglster


When you run 'ping 8.8.8.8', you are testing internet connection but not DNS resolution.

Try 'ping www.google.com', I think you are having a DNS issue, thats why Jenkins can't reach the plugins packages.

Edit /etc/docker/daemon.json and set your local DNS servers to avoid Docker using default Google Public DNS. Docker Docs - Daemon configuration file .

like image 40
edumgui Avatar answered Sep 22 '22 01:09

edumgui