Questions & Answers

reachability problem with docker node container and angular/nodejs

To follow the angular tutorial available on the angular website, I decided to download the "node" image from dockerhub. I mapped the container ports 4200 and 8080 to the physical windows machine ports 4200 and 8888 respectively, with the following command:

docker container run -it -p 8888:8080 -p 4200:4200 -d --name nodejsdocker -v C:\root\docker\nodejs:/home/node node  bash

inside the container I ran the following commands:

npm install -g @angular/cli
ng new my-app
ng serves --open

and I see the application starting on port 4200:

root@99a0f1e2bc80:/# netstat -anp |grep 4200
tcp        0      0*               LISTEN      124/ng serve --open

at this point, on the physical windows machine, I expect to be able to make the request via browser at the following url http://localhost:4200/ but the request returns "time out"

wget also works inside the container:

root@99a0f1e2bc80:/# wget http://localhost:4200/
--2023-01-18 16:34:01-- http://localhost:4200/
Resolving localhost (localhost)..., ::1
Connecting to localhost (localhost)||:4200... connected.
HTTP request sent, awaiting response... 200 OK
Length: 561 [text/html]
Saving to: 'index.html.2'

index.html.2 100%[=========================================== =================================================== =======================>] 561 --.-KB/s to 0s

2023-01-18 16:34:01 (49.5 MB/s) - 'index.html.2' saved [561/561]


Why am I not able to send the HTTP request http://localhost:4200/ on the physical machine? I'm expecting to receive an html index page from the container angular app.

2023-01-19 10:42:02
Welcome to SO, nice question, next time please format your code into code blocks! Thanks
Answers(0) :