I have looked at other similar questions like: Access to Docker Container Port and access docker container's port and Cannot access port on host mapped to docker container port and I think I am doing everything I can to be able to access port 4200 on my docker container yet I am not able to.
Here is the output of docker ps
:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
298f832ca50d redcricket/fisherman:latest "/usr/sbin/init" About an hour ago Up 39 minutes 4200/tcp gallant_matsumoto
My container is pingable:
$ ping `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' gallant_matsumoto`
Pinging 172.17.0.2 with 32 bytes of data:
Reply from 172.17.0.2: bytes=32 time=110ms TTL=239
Reply from 172.17.0.2: bytes=32 time=82ms TTL=239
Reply from 172.17.0.2: bytes=32 time=92ms TTL=239
Reply from 172.17.0.2: bytes=32 time=80ms TTL=239
Ping statistics for 172.17.0.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 80ms, Maximum = 110ms, Average = 91ms
On my server I start angular like so:
[root@298f832ca50d HelloWorld]# ng serve --host 0.0.0.0 --port 4200 --disableHostCheck
WARNING: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.
Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
websocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
WARNING: Running a server with --disable-host-check is a security risk. See https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a for more information.
10% building 3/3 modules 0 activeℹ 「wds」: Project is running at http://0.0.0.0:4200/webpack-dev-server/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: 404s will fallback to //index.html
chunk {main} main.js, main.js.map (main) 9.77 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 251 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.09 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 16.3 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.8 MB [initial] [rendered]
Date: 2019-07-06T19:58:08.308Z - Hash: 201a042264b357c18e36 - Time: 14593ms
** Angular Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **
ℹ 「wdm」: Compiled successfully.
But I still cannot access http://172.17.0.2:4200/
C:\Users\plankton>curl http://172.17.0.2:4200/
curl: (7) Failed to connect to 172.17.0.2 port 4200: Timed out
What did I miss?
Update: Thanks seahorsepip I tried this:
$ docker run --privileged -p=4200:4200 -itd -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup redcricket/fisherman:latest /usr/sbin/init
870cd55d0bc65ffe27c595b0092f28a5e333c235ae355a2469563b09058cdf22
plankton@DESKTOP-C8MFTFD MINGW64 /c/Program Files/Docker Toolbox
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
870cd55d0bc6 redcricket/fisherman:latest "/usr/sbin/init" 8 seconds ago Up 3 seconds 0.0.0.0:4200->4200/tcp kind_kapitsa
But I am still not able to connect ...
C:\Users\plankton>curl http://localhost:4200/
curl: (7) Failed to connect to localhost port 4200: Connection refused
Update II: Thanks to David below I now know the VM's ip
$ docker-machine.exe ip
192.168.99.100
I am not sure how to use this IP though.
On the client I get ...
C:\Users\plankton>curl http://192.168.99.100:4200
curl: (7) Failed to connect to 192.168.99.100 port 4200: Connection refused
If I try to restart the server like so ...
[root@bfd864884a59 HelloWorld]# ng serve --host 192.168.99.100
An unhandled exception occurred: listen EADDRNOTAVAIL: address not available 192.168.99.100:4200
See "/tmp/ng-YKKmQ9/angular-errors.log" for further details.