I'm working through a tutorial for React.js, and I decided to work within a Docker container. Here is the code for the tutorial.
The tutorial uses webpack-dev-server
running on port 8080 on the container. I've exposed this port in my Dockerfile
, and I ran my container with -P
to publish the port. Inside the container, if I wget http://localhost:8080
, it downloads index.html
as expected. However, if I run the equivalent PowerShell command Invoke-WebRequest http://localhost:32769
from my host, I get Invoke-WebRequest : The underlying connection was closed: The connection was closed unexpectedly.
Full details/repro steps below.
Dockerfile
FROM node
MAINTAINER Matthew Pirocchi <matthew.pirocchi@gmail.com>
RUN apt-get update && apt-get install -y vim
EXPOSE 8080
Container setup
docker run -itdP --name repro mpiroc/react-fundamentals
docker exec -it repro bash
# Following commands executed within container
mkdir -p /home/mpiroc/repos && cd /home/mpiroc/repos
git clone https://github.com/ReactjsProgram/React-Fundamentals.git
cd React-Fundamentals
git checkout video2
npm install
npm run start # start just runs `webpack-dev-server`
Testing the container
# In a separate terminal
PS C:\Users\matth> docker exec -it repro bash
root@fd6c3102bc51:/# wget http://localhost:8080
... # index.html is downloaded as expected
root@fd6c3102bc51:/# exit
exit
PS C:\Users\matth> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd6c3102bc51 mpiroc/react-fundamentals "node" 28 minutes ago Up 28 minutes 0.0.0.0:32769->8080/tcp repro
PS C:\Users\matth> Invoke-WebRequest http://localhost:32769
Invoke-WebRequest : The underlying connection was closed: The connection was closed unexpectedly.
At line:1 char:1
+ Invoke-WebRequest http://localhost:32769
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Why can't I access the published port from my host machine?