2017-10-05 150 views
1

我試圖設置一個Docker for Windows容器來構建和託管一個使用lite-server和Sphinx的簡單靜態網站。我首先運行容器。通過本地主機Docker for Windows的Windows容器本地託管的網站無法通過本地主機

$ docker run -it -p 8080:8080 -v "$(pwd):C:\src" website 

然後啓動lite-server。

$ yarn serve 

該網站可從容器的IP地址(例如,http://172.26.141.28:8080),所以我知道精簡版服務器提供的內容,但我不能http://localhost:8080訪問內容。

如何通過本地主機:8080公開網站?

我Dockerfile如下

FROM microsoft/windowsservercore 

ENV chocolateyUseWindowsCompression false 
RUN powershell -Command \ 
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); 

RUN choco install nodejs -y 
RUN choco install yarn -y 
RUN choco install python3 -y 
RUN pip install sphinx 
RUN pip install sphinx_rtd_theme 

# https://github.com/nodejs/node/issues/8897#issuecomment-319010735 
# Workaround for error An unexpected error occurred: "ENOENT: no such file or directory, lstat 'C:\\ContainerMappedDirectories'". 
RUN mkdir C:\src 
RUN powershell Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices' -Name 'S:' -Value '\??\C:\src' -Type String 
WORKDIR 'S:\\' 

EXPOSE 8080 
CMD ["powershell"] 

精簡版服務器與

"scripts": { 
    "serve": "light-server -s ./build/html -p 8080" 
}, 

軟件推出:

  • 多克爾版本17.06.2策,建立cec0b72
  • Windows 10(主機)
  • Windowsservercore(容器)
+0

這是Windows容器中的一個已知錯誤,其中從localhost訪問映射端口不起作用。嘗試從外部機器訪問此端口 –

回答

0

你搬運工文件說你是在8080暴露的端口,你在8091.

嘗試運行下面的命令被映射,

搬運工運行 - 它-p :8080 -v 「$(PWD):C:\ SRC」 網站

你應該能夠將其定位到http://localhost:8080

希望它有幫助。

+0

糟糕。 8091是一個錯字。我已經糾正它。我爲主機8080,8091等嘗試了不同的端口。同樣的結果,我無法通過localhost:port訪問容器中的網站。 –