Windows的Docker桌面:在Windows容器模式下无法访问裸露端口上的服务 [英] Docker Desktop for Windows: cannot access service on exposed port in windows container mode
问题描述
我正在使用以下 Dockerfiles 在运行 Docker Desktop for Windows 版本17.03
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" ]
我从此docker文件创建映像:
I create the image from this docker file:
docker build -t windows-java:jre1.8.0_91 .
我用来在此之上安装Jenkins的第二个Dockerfile:
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
但是,我无法访问在主机Web浏览器上的http://localhost:8080
上运行的jenkins服务器.
However, I cannot access the jenkins server running on http://localhost:8080
on the host machine's web browser.
不确定是否有帮助,但是当我在同一台计算机上以Linux container
模式运行docker时,我能够访问http://localhost:8080
上的jenkins服务器
使用他们的官方docker映像.
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.
推荐答案
这是Windows上目前已知的问题.无法使用localhost/127.0.0.1.从其自己的主机访问容器终结点.今天可以使用Linux容器,因为Docker包含了一种特殊的变通方法,这种变通方法是Moby/Linux实施所特有的,可以在Windows上运行Linux容器.
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:
- 使用运行容器的主机的IP地址以及容器在其主机上的公开端口,从单独的主机访问容器端点 通过使用容器的内部IP地址和发布的端口访问相同主机上的容器,以进行
- OR(可以使用
docker network inspect <network name>
或docker exec <container ID> ipconfig>
来获取容器端点本身的IP地址)
- Accessing container endpoints from a separate host, using the IP address of the host that is running the container, and the exposed port for the container on its host
- OR by accessing the container on the same host, using the container's internal IP address and published port (you can use
docker network inspect <network name>
ordocker exec <container ID> ipconfig>
to get the IP address of the container endpoint itself)
这篇关于Windows的Docker桌面:在Windows容器模式下无法访问裸露端口上的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!