1

I am attempting to set up a Docker for Windows container to build and host a simple static website using lite-server and Sphinx. I first run the container.

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

And then start lite-server.

$ yarn serve

The website is available from the container's IP address (e.g., http://172.26.141.28:8080) so I know lite-server is serving the content, but I cannot access the content with http://localhost:8080.

How can I expose the website via localhost:8080?

My Dockerfile is as follows

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 is launched with

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

Software:

  • Docker version 17.06.2-ce, build cec0b72
  • Windows 10 (host)
  • Windowsservercore (container)
Ryan Taylor
  • 8,740
  • 15
  • 65
  • 98
  • This is known bug in windows containers where accessing mapped port from localhost is not working. Try to access this port from external machine – Gregory Suvalian Oct 05 '17 at 11:46

2 Answers2

1

I don't know if there's been an update, but as of a year ago, this was the expected behavior:

containers and their ports are only accessible via the NATed IP address.

see: https://github.com/docker/for-win/issues/204#issuecomment-258638899.

0

Your docker file says you are exposing the port at 8080 and you are mapping at 8091.

try to run the following command,

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

You should able to navigate it to http://localhost:8080

Hope it helps.

Kannaiyan
  • 12,554
  • 3
  • 44
  • 83
  • Oops. 8091 was a typo. I've since corrected it. I have tried different ports for the host, 8080, 8091, and others. Same result, I cannot access the website in the container via localhost:port. – Ryan Taylor Oct 05 '17 at 10:13