2017-10-05 143 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访问容器中的网站。 –