I'm having trouble accessing apps that should expose ports to the host via docker-compose. Here is a reproducible example:
I create a new angular app using the angular CLI:
ng new angular-docker
Then I create a Dockerfile with the following contents in that directory:
FROM node:8
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
EXPOSE 4200
CMD ["npm", "start"]
Next I create a docker-compose.yaml file in the same directory:
version: '3'
services:
angular:
build: .
container_name: angular-docker
volumes:
- ./src:/usr/src/app/src
ports:
- "4200:4200"
Then I run:
docker-compose up
I wait until I get the following line in the docker-compose output
angular-docker | ** Angular Live Development Server is listening on localhost: 4200, open your browser on http://localhost:4200/ **
From docker inspect angular-docker I see that the port-forwarding rule is in place:
...
"Ports": {
"4200/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "4200"
}
]
},
...
Now, when I try to go to http://localhost:4200 in Chrome, I get ERR_EMPTY_RESPONSE.
However, when I use docker exec -it angular-docker bash to bash into the container, I get a response, when I curl localhost:4200.
My environment:
- OS: Windows 10 Pro Version 10.0.16299 Build 16299
- Docker: 18.03.1-ce-win65 (17513)
I figured that this might be a firewall issue. So for debugging, I closed the firewall application (I'm using Kaspersky Internet Security), with no luck.
Why can I not access the container from the exposed port?
EDIT:
netstat -an | findstr ":4200" returns the following:
Proto Local Address Foreign Address State
TCP 0.0.0.0:4200 0.0.0.0:0 LISTENING
TCP [::1]:4200 [::]:0 LISTENING