I am using the following Dockerfiles to create a container running Jenkins in a windows container on Windows 10 desktop running Docker Desktop for Windows version 17.03
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 create the image from this docker file:
docker build -t windows-java:jre1.8.0_91 .
The second Dockerfile I am using to install 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 .
Then I launch the container like this:
docker run --name jenkinsci -p 8080:8080 -p 50000:50000 jenkins-windows:2.0
I can see the container running fine and logs showing up all 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
However, I cannot access the jenkins server running on http://localhost:8080
on the host machine's web browser.
Not sure if it helps but when I was running docker in Linux container
mode on the same machine, I was able to access jenkins server on http://localhost:8080
using their official docker image.
Looks this issue does not seem to be so boring as it was. Followings docs at https://docs.docker.com/engine/reference/run/#expose-incoming-ports you can specify an IP address at the host machine where you want container's port(s) to be exposed.
Probably that is 127.0.0.1, and it resolves an issue with access to exposed Docker container port on the Windows system. Just use -p switch with IP address when running container.
This is a currently a known issue on Windows. It's not possible to access a container endpoint from its own host using localhost/127.0.0.1. It is possible using Linux containers today because Docker has included a special workaround that is unique to their Moby/Linux implementation for running Linux containers on Windows.
We're working on a fix for this, but today we recommend working around this by either:
docker network inspect <network name>
ordocker exec <container ID> ipconfig>
to get the IP address of the container endpoint itself)To complete @Kallie-Microsoft post:
docs.docker.com have been updated with a section Limitations of Windows containers for localhost and published ports
I faced the same issue, the ordering of docker run command matters.
docker run -p <host port>:<container port> <image>
Worksdocker run <image> -p <host port>:<container port>
Doesn't WorkMy setup -
Using Windows 10 , Version 2004 (OS build 19041.329) WSL 2 enabled - https://docs.microsoft.com/en-us/windows/wsl/wsl2-index Ubuntu 18.04 installed from Microsoft store and its enabled in docker.