Tommy J
Tommy J

Reputation: 441

Can't access Angular from outside of the container

I am running Angular on a docker container and trying to access it from my local web browser.
FROM node:9.11.1 as node MAINTAINER Tectonic RUN mkdir -p /usr/src/app WORKDIR /usr/src/app COPY package.json /usr/src/app RUN npm install COPY . /usr/src/app EXPOSE 4200 CMD ["npm", "start"]

I build using: docker build -t act .

And I run using: docker run -p 4200:4200 act

This used to work for me but doesn't now. The error I'm getting from chrome is This site can’t be reached 172.17.0.2 took too long to respond.. I've tried going to localhost:4200, http://localhost:4200, http://0.0.0.0:4200

I've tried running other web servers and I can access them just fine : docker run -p 80:80 --name webserver nginx

Upvotes: 2

Views: 1602

Answers (2)

dargueta
dargueta

Reputation: 31

Is case someone is having this issue, you can run:

ng serve --host 0.0.0.0 --port 4200

And you will be able to acccess your application from host.

Upvotes: 3

VitoInfinito
VitoInfinito

Reputation: 143

Could it be that you need to allow all interfaces with the --host flag?

npm start --host 0.0.0.0

This allows angular to be accessed by all interfaces and not only as with serving the loopback interface which is necessary once it's inside a docker container.

Upvotes: 0

Related Questions