由Docker for Windows Windows容器本地托pipe的网站不可通过本地主机
我正在尝试设置一个Docker for Windows容器来构build和使用lite-server和Sphinx来托pipe一个简单的静态网站。 我首先运行容器。
$ docker run -it -p 8080:8080 -v "$(pwd):C:\src" website
然后启动lite-server。
$ yarn serve
该网站可从容器的IP地址(例如, http://localhost:8080
),所以我知道lite服务器正在服务的内容,但我不能访问与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"]
lite-server被启动
"scripts": { "serve": "light-server -s ./build/html -p 8080" },
软件:
- Docker版本17.06.2-ce,build cec0b72
- Windows 10(主机)
- Windowsservercore(容器)
我不知道是否有更新,但截至一年前,这是预期的行为:
容器及其端口只能通过NAT的IP地址访问。
请参阅: https : //github.com/docker/for-win/issues/204#issuecomment-258638899 。
你的docker文件说你在8080端口暴露,你在8091上映射。
尝试运行以下命令,
docker运行-it -p 8080 :8080 -v“$(pwd):C:\ src”网站
您应该能够导航到http:// localhost:8080
希望能帮助到你。