Docker for windows error can t access service on exposed port in windows container mode

0 votes

I’ve created Dockerfiles to build a container that runs Jenkins in a windows container.

FROM microsoft/windowsservercore
RUN powershell -Command wget 'http://javadl.oracle.com/webapps/download/AutoDL?BundleId=210185' -Outfile 'C:\jreinstaller.exe' ; Start-Process -filepath C:\jreinstaller.exe -passthru -wait -argumentlist "/s,INSTALLDIR=c:\Java\jre1.8.0_91" ; del C:\jreinstaller.exe
ENV JAVA_HOME c:\\Java\\jre1.8.0_91 
RUN setx PATH %PATH%;%JAVA_HOME%\bin
CMD [ "java.exe" ]

I’ve created the image using:

docker build -t windows-java:jre1.8.0_91 .

The second Dockerfile is for installing Jenkins on top of this:

FROM windows-java:jre1.8.0_91
ENV HOME /jenkins 
ENV JENKINS_VERSION 2.58 
RUN mkdir \jenkins 
RUN powershell -Command "wget -Uri https://updates.jenkins-ci.org/latest/jenkins.war -UseBasicParsing -OutFile /jenkins/jenkins.war
EXPOSE 8080 
EXPOSE 50000 
CMD java -jar C:\\jenkins\\jenkins.war
docker build -t jenkins-windows:2.0 .

Finally, I launch the container:

docker run --name jenkinsci -p 8080:8080 -p 50000:50000  jenkins-windows:2.0

The output looks good

PS C:\Users\mandeep\ringba\ringba-jenkins-setup-windows\jenkins-master> docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                              NAMES
85ba2ef525a1        jenkins-windows:2.0   "cmd /S /C 'java -..."   8 hours ago         Up 8 hours          0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkinsci

But I can’t seem to access the Jenkins server running on http://localhost:8080 on the host machine's web browser.

 Any help would be appreciated

This is a common issue on Windows. You cant access a container endpoint from its own host using localhost/127.0.0.1. It is possible using Linux containers though. 

Dec 12, 2018 in DevOps & Agile by Sophie may
• 10,620 points
5,512 views

1 answer to this question.

0 votes

You can try the following:

  • Access container from different host, using the IP address of the host that is running the container
  • Access container on the same host, using the container's internal IP address and published port
answered Dec 12, 2018 by Tyrion anex
• 8,700 points

Hi , I tried. actually it was not working. I created docker image using "ibmcom/websphere-liberty:latest" as base image and started container using docker-compose file and used 9080 for port forwarding. when I say docker ps, it shows as below.


C:\WINDOWS\System32>docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
be6382167025        reimage15           "/opt/ibm/helpers/ru…"   About an hour ago   Up About an hour    0.0.0.0:9080->9080/tcp, 0.0.0.0:9450->9450/tcp, 9443/tcp   default_ruleeditor_1

then I was trying to run application from windows host machine as "javaws http://localhost:9080/rtccClient/rtcc.jnlp". my docker container is Linux container. I even used container internal IP in url.. below error is coming. please help.

CouldNotLoadArgumentException[ Could not load file/URL specified: http://localhost:9080/rtccClient/rtcc.jnlp]
 at com.sun.javaws.Main.launchApp(Unknown Source)
 at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
 at com.sun.javaws.Main.access$000(Unknown Source)
 at com.sun.javaws.Main$1.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Unexpected end of file from server

Hi,

Your docker container is running fine. Now you are trying to connect your Docker container from windows. But instead of localhost, you should use the IP of your Docker host machine.

HI, Thanks for reply.

when I say docker inspect <containerID> it shows below.

 "NetworkID": "d7e5bd215ba7685cdfbaf91b0147bbc3576b8331e249d4df6bd1c576e42d9e1a",
                    "EndpointID": "be1b1b2c31c640e47938574feac62b1915370af2c41a336332d0370fe17abd2d",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:03",
                    "DriverOpts": null.

so 172.18.0.3 is my container ID. So I used it as  "http://172.18.0.3:9080/rtccClient/rtcc.jnlp". still it doesn't work. some where I red that container internal lP couldn't be accessed from windows host machine. more over I am not working in VM. In your reply you said I need to use IP of docker host machine. It means my windows host machine IP or docker container IP?

Hi,

As we know docker worked on isolated environment. So you can't connect with the container IP. Ok. tell me docker is running on Virtual box or Windows system?

Related Questions In DevOps & Agile

0 votes
1 answer

Error: Unable to access elasticsearch in docker for windows

This is simple, just follow the below ...READ MORE

answered Sep 3, 2018 in DevOps & Agile by Sophie may
• 10,620 points
1,645 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,654 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP