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 '' -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 
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 
RUN mkdir \jenkins 
RUN powershell -Command "wget -Uri -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>8080/tcp,>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/ It is possible using Linux containers though. 

Dec 12, 2018 in DevOps & Agile by Sophie may
• 9,940 points

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,380 points

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
• 9,940 points
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 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
• 57,530 points