1

I have a front app who uses Angular-cli and i’am trying to check if it works proprely separetly before integrating it in the container core but it seems that i can’t get acces to the localhost. I’am using a macOS Catalina 10.15.7 with Docker Desktop.

And it's not the same problem as others because i already tested before asking my question in stackoverflow so don't put as duplicate, THANK YOU !!

My Dockerfile is build like this:

FROM    node:14-alpine3.12

WORKDIR /app/front

#COPY    ./angular-cli .
COPY    package.json package-lock.json
COPY    . .       

RUN     npm install 
RUN     npm install -g @angular/cli

EXPOSE  4200
# Angular installation if it fails, 

CMD     ["ng", "serve"]

And when i run the app with the command:

docker run -d -p 80:4200 reponame

My build works perfectly and shows me this:

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Compiled successfully.

and when i go to Localhost:4200 it shows that the page is not accessible. i also tried to connect with Ip adress using this commands but same thing.

docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ imagename

i also tried to change different ports because i read in Mac the port 80 might be broken or smth so i tried:

docker run -d -p 4200:4200 appname
docker run -d -p 8080:4200 appname

If anyone can help me, would really greatfull. Thanks !

Zemmouri Tarek
  • 98
  • 2
  • 13

2 Answers2

0

I assume your app in the container is NOT exposed via the 0.0.0.0 interface.

So in your Angular app, change expose on localhost to 0.0.0.0 instead.

Update your CMD:

CMD ["ng", "serve", "--host", "0.0.0.0"]

Connect from your host system with localhost:80.

Robert-Jan Kuyper
  • 2,418
  • 12
  • 22
0

your port mapping seems incorrect with what you are trying to achieve. -p 80:4200 means that you would use port 80 on your host machine to access the application.

So you should try to access it through http://localhost or http://localhost:80. Even if that is not working, it sometimes happen that your port 80 is already bound to some other application. May be you can try a different port like 8080, 8888 etc instead of 80.

Sukhmeet Sethi
  • 616
  • 5
  • 14
  • Well as i mentionned, it is as you said in http//localhost but if the port was already taken Docker would have told me that it is, no ? – Zemmouri Tarek Dec 01 '21 at 12:33