Docker jenkins not accessible from host browser - docker

I have docker running on centos vm(on vmware) with host machine of windows. I can able to ping centos vm IP address from host(windows) machine ip.
I tried below on centos vm,
docker run -it -p 8080:8080 -p 50000:50000 jenkins/jenkins
2020-11-21 18:41:28.924+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2020-11-21 18:41:29.116+0000 [id=20] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running
Below is the output of "docker ps"
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
16a6d00b0933 jenkins/jenkins "/sbin/tini -- /usr/…" 8 minutes ago Up 8 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp bhaskara
But when i try to access from host machine(windows) browser like below,
http://centos_vm_ip:8080
Am getting like "Site can't be reached"
Also, On centos vm I have opened port 8080
# firewall-cmd --list-all
public (default, active)
interfaces: eno16777736
sources:
services: dhcpv6-client ssh
ports: 80/tcp 8080/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
Any idea, how to solve this issue?
TIA

You probably need to configure port forwarding in VMware, so you can access Jenkins from your host.

I hope you have followed the steps mentioned Configuring a Web server on a virtual machine that uses NAT mode networking

Related

In SWARM not able to access service from worker node

I am new to the docker world. During learning I have created the below setup:
1.Virtual machine - Ubuntu 20 running on VMware workstation 15 Player. IP - 192.168.0.106. I am able to access the internet from this VM(say it VM1) and able to ping that system from my physical system OS( Windows 10)
2.Virtual Machine - Ubuntu 20 running on VMware workstation 15 Player. IP - 192.168.0.105. I am able to access the internet from this VM(say it VM2) and able to ping that system from my physical system OS( Windows 10)
Now I have created the swarm as follows from VM1:
sudo docker swarm init --advertise-addr 192.168.0.106:2377 --listen-addr 192.168.0.106:2377
Then I added the VM2 in this swarm as follows:
sudo docker swarm join --token SWMTKN-1-4i56y47l6o4aycrmg7un21oegmfmwnllcsxaf4zxd05ggqg0zh-9qp67bejerq9dhl3f0suaauvl 192.168.0.106:2377 --advertise-addr 192.168.0.105:2377 --listen-addr 192.168.0.105:2377
After that I checked the swarm details:
sudo docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ogka7rdjohri9elcbjjcpdlbp * ubuntumaster Ready Active Leader 19.03.12
7qu9kiprcz7oowfk2ol31k1mx ubuntuslave Ready Active 19.03.13
Then deployed the nginx service as follows from VM1:
sudo docker service create -d --name myweb1 --mode global -p9090:80 nginx:1.19.3
Service status:
sudo docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
e1o9cbm3e0t myweb1 global 2/2 nginx:1.19.3 *:9090->80/tcp
Service details:
sudo docker service ps zf6kfw7aqhag
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
egd8oliwngf3 myweb1.ogka7rdjohri9elcbjjcpdlbp nginx:1.19.3 ubuntumaster Running Running 14 minutes ago
1o4q8dlt94jj myweb1.7qu9kiprcz7oowfk2ol31k1mx nginx:1.19.3 ubuntuslave Running Running 14 minutes ago
Now I am able to access the nginx from VM1 using URL: 192.168.0.106:9090 and localhost:9090. But I am not able to access nginx from VM2 using URL: 192.168.0.105:9090 and localhost:9090. My understanding that the nginx are running on both the VMs and can be accessible on both.
in both the VM1 I am able to see the nginx container is running.
VM1 :
sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a4e13e49dfd nginx:1.19.3 "/docker-entrypoint.…" 16 minutes ago Up 15 minutes 80/tcp myweb1.ogka7rdjohri9elcbjjcpdlbp.egd8oliwngf35wwpjcieew323
VM2:
sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
999062110f0 nginx:1.19.3 "/docker-entrypoint.…" 16 minutes ago Up 16 minutes 80/tcp myweb1.7qu9kiprcz7oowfk2ol31k1mx.1o4q8dlt94jj4uufysnhsbamd
Please guide me on this if I am doing any mistakes.
TIA,
Deb
Problem solved! it was an issue was the ip clashing. Restarted the whole systems including the VM and router to solve this issue.

Container is not available on localhost in Windows Docker Toolbox

I try to connect to my container on localhost/127.0.0.1/0.0.0.0 but site can’t be reached.
Details:
$ docker run -d -p 80:80 nginx:alpine
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
d5b465ed1b18 nginx:alpine "nginx -g 'daemon of" 6 minutes ago Up 6 minutes 0.0.0.
0:80->80/tcp quizzical_swirles
798b40ceec77 10.36.7.241:5000/facileexplorer:0.3.8 "/usr/bin/supervisor" 9 minutes ago Up 9 minutes 4444/t
cp, 0.0.0.0:3838->3838/tcp, 0.0.0.0:8787->8787/tcp, 5900/tcp vigilant_banach
I followed this tutotial: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/:
$ docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' d5b465ed1b18
<no value>
but it doesn't return port.
And I also helped myself with this guide: https://www.iancollington.com/docker-and-cisco-anyconnect-vpn/ because some of my docker images are on private registry, so I did following steps:
PATH=$PATH:"C:\Program Files\Oracle\VirtualBox"; export PATH
export DOCKER_HOST="tcp://127.0.0.1:2376"
docker-machine stop default
VBoxManage modifyvm "default" --natpf1 "docker,tcp,,2376,,2376"
docker-machine start default
alias docker='docker --tlsverify=false'
Could you help?
When you are using Docker Toolbox, running docker run -p 80:80 can be misleading. It means it will forward the port 80 of your container to the port 80 of your Docker machine, not the Windows host!
If you want to access the container through your Windows host, you also need to forward port 80 of your Docker machine to that host.
I see you are using VirtualBox, which allows you to do that by adding an entry in Settings > Network > Advanced > Port Forwarding.
Example tutorial with images: https://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/

How to identify the docker host ip to use when running a jenkins container

I have docker machine installed on windows OS and have pulled in Jenkins image from docker hub. I then run the below commands:
docker volume created myjenkins-data
docker run -p 8080:8080 -p 50000:50000 -v myjenkins-data:/var/jenkins_home jenkins
I received the admin key for Jenkins in the logs. I've confirmed that my container is still running status:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2854c7d83879 jenkins "/bin/tini -- /usr..." About a minute ago Up About a minute 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp quizzical_cray
Now, I need to log into 8080 port to view the Jenkins web app. But I do not know which host ip to use. I identified the docker host ip with the command "docker-machine ip" and got the ip address: 192.168.99.100. But using 192.168.99.100:8080 did not bring up Jenkins app. I also tried using docker inspect to get the container's ip, but port 8080 didn't work on those ips as well. Which ip address do i use to see the Jenkins app that is running in the container?
First, double-check if http://localhost:8080 is not enough.
Hyper-V (through vpnkit, if you are using Docker for Windows) should have done the port-forwarding for you.
If you are using the legacy docker toolbox (VirtualBox), then you need port-forwarding (issue 4115).

Zookeeper in Docker

I run zookeeper in a docker container on my Windows 7 machine. I use docker-compose and defined the
ports: ['2181:2181'] mapping inside. The docker terminal shows me the zookeeper instance running:
b3169443e7ee confluentinc/cp-zookeeper:3.3.0 2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp zookeeper
But when I execute netstat -an in Windows terminal I do not see the 2181 port open. Neither can I connect to zookeeper using putty telnet on localhost port 2181. What could be the problem? As far as I understand the zookeeper ports are not exposed to the host. But they should be as I included the ports mapping in the docker-compose .yaml file.
This is a known issue with localhost on windows. You need to use the container IP address. You can find it by running the command
docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' <container>
For more info check: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/
OK, finally I found out the reason. Since on Windows 7 you have to run your docker container in a virtual box running a linux system, the docker container sees the virtual box system as its host, not the original Windows 7 machine. Therefore the port mapping guest-to-host maps the port 2181 of the docker container to the 2181 port of the linux system in virtual box and NOT to the 2181 port of the "real" Windows 7 host. So, in order to connect to zookeeper, I had to retrieve the IP of the virtual box machine using
docker-machine ls and then connect to port 2181 on that IP.

How to access Docker container's web server from host

I'm running under boot2docker 1.3.1.
I have a Docker container running a web server via uwsgi --http :8080.
If I attach to the container I can browse the web site using lynx http://127.0.0.1:8080 so I know the server is working.
I ran my container with:
$ docker run -itP --expose 8080 uwsgi_app:0.2
It has the following details:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5248ad86596d uwsgi_app:0.2 "bash" 11 minutes ago Up 11 minutes 0.0.0.0:49159->8080/tcp cocky_hypatia
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 5248ad86596d
172.17.0.107
I thought I could access that web site from my host by going to http://172.17.0.107:49159.
This does not work. I just see 'connecting...' in Chrome, getting nowhere.
What am I doing wrong?
Extending Anentropic's answer: boot2docker is the old app for Mac and Windows, docker-machine is the new one.
Firstly, list your machines:
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
default * virtualbox Running tcp://192.168.99.100:2376
Then select one of the machines (the default one is called default) and:
$ docker-machine ip default
192.168.99.100
Ok, stupid me, I found the answer in the docs for boot2docker
https://docs.docker.com/installation/mac/#container-port-redirection
I needed to use the ip address of the boot2docker vm, rather than the ip of the container, i.e.
$ boot2docker ip
192.168.59.103
and I am able to browse my site from the host at http://192.168.59.103:49159/
I did not need to add any route on the host
To find the IP address of your container, you should need NO additional installs:
docker inspect <container>
This provides a wealth of info. grep it for the IPAddress.
You could use boot2docker port mapping option -L, as described here.
So, in your case it would be
boot2docker ssh -L 0.0.0.0:8080:localhost:8080
and then
docker run -it -p 8080:8080 uwsgi_app:0.2
That way, you do not have to use boot2docker's IP address: you can use localhost or your own IP address (and your docker container can be accessed from outside).
Boot2docker is outdated, but you may still have this problem on Docker for Windows or Mac, even though the same container works on Linux. One symptom is that trying to access a page on the server inside the container gives the error "didn't send any data" as opposed to "could not connect."
If so, it may be because on Win/Mac the container host has its own IP, it's not localhost as it is on linux. Try running Django on IP 0.0.0.0, meaning accept connections from all IPs, like this:
python manage.py runserver 0.0.0.0:8000
Alternatively, if you need to make sure the server only responds to local requests (such as from your local proxy like nginx, apache, or gunicorn) you can use the host IP returned by hostname -i.
And make sure you are using the -p port forwarding option correctly in the docker run command.
Assuming all is well, you should be able to access your server at http://localhost in a browser running on the host machine.
docker build -t {imagename} .
docker build -t api-rest-test .
docker run -dp {localport}:{exposeport} image:name
docker run -dp 8080:8080 api-rest-test:latest
make sure you are using the same port for yourlocalport and exposeport
then you can access your rest service in your local machine http://localhost:8080
[EDIT: original version was ignoring the -P in question]
If you want to get to the containers without having to 'publish' the port (which changes its number)
there is a good run-through here.
The key is this line:
sudo route -n add 172.17.0.0/16 172.16.0.11
which tells the Mac how to route to the private network inside the VirtualBox VM that the Docker containers are on.
Had the same issue and in my case i was using AWS EC2 instance. I was trying with the container IP which did not work. Then I used the actual public IP of the AWS host as the IP, which worked.
How to troubleshoot the issue on hosting application on local host browser
For this launch the container with below command, in my case it was:
[root#centoslab3 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b81d8a0e3e1 centos:baseweb "/bin/bash" 8 minutes ago Exited (0) 24 seconds ago webtest
[root#centoslab3 ~]# docker run --name=atul -v /root/dockertest:/var/www/html -i -t -p 5000:8000 centos:baseweb /bin/bash
In the httpd configuration:
[root#adb28b08c9ed /]# cd /etc/httpd/conf
[root#adb28b08c9ed conf]# ll
total 52
-rw-r--r--. 1 root root 34419 Sep 19 15:16 httpd.conf
edit the file with the port 8000 in listner and update the container ip and port under Servername.
Restart the httpd service and you are done.
Hope this helps

Resources