我正在尝试为Windows容器设置Docker,以使用lite-server和Sphinx构建并托管一个简单的静态网站。我首先运行容器。
$ docker run -it -p 8080:8080 -v "$(pwd):C:\src" website
然后启动lite-server。
$ yarn serve
该网站可通过容器的IP地址访问(例如
http://172.26.141.28:8080
),因此我知道lite-server正在提供内容,但我无法使用http://localhost:8080
访问内容。如何通过localhost: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"
},
软件:
最佳答案
我不知道是否有更新,但是截至一年前,这是预期的行为:
参见:https://github.com/docker/for-win/issues/204#issuecomment-258638899。
关于docker - 由Docker for Windows Windows容器本地托管的网站无法通过localhost访问,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46576521/