Tuesday, February 6, 2024

[SOLVED] Access Angular app running inside Docker container

Issue

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.


Solution

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



Answered By - Mike Tung
Answer Checked By - Cary Denson (WPSolving Admin)