1

I've created a docker image to test an Angular app but I cannot connect from host to running app inside docker container.

The image was created using a Dockerfile with: EXPOSE 4200 8080 80

I run the docker container with command: docker run -ti -p 4200:4200 angulardev /bin/bash

Inside container I create the Angular application and start it using: ng serve

From container, if I open localhost:4200 I see the application but I cannot access it from host OS (RHEL7)

What is wrong? The Angular app starts on port 4200 which is exposed and mapped to host 4200.

Thanks.

sasser
  • 13
  • 4
  • For Complete Docker beginners, learn how to run Angular inside Docker https://thecodeframework.com/run-angular-app-inside-a-docker-container-in-5-mins/ – Gagan May 09 '20 at 18:45

1 Answers1

9

If you are running angular app inside your container with just ng serve it won't allow other hosts from accessing it.

Instead you should run it using ng serve --host 0.0.0.0 --port 4200

Mike Tung
  • 4,735
  • 1
  • 17
  • 24
  • Thank You, Mike. I was running into this same issue and your suggestion made my day. Thanks again for the contribution. – VXJ8464 Jan 13 '22 at 20:43