Why is my Docker instance running in Compute Engine not able to be accessed outside of the container?

8/7/2019

I've successfully uploaded a docker image of my app to GCR, made a GCE instance out of it, enabled http forwarding, and after SSH'ing into the GCE instance did a 'docker pull ' + 'docker run -d -p 8888:8888 ' but I am not able to access the app via the external IP + the port (8888). So then I tried SSHing into the GCE instance, and running 'docker exec -it curl -v http://localhost:8080/healthCheck' and I am able to access my app.

I've tried SSHing into my GCE instance and running 'docker exec -it curl -v http://localhost:8080/healthCheck' so I know that the app is running fine, it's just missing something that maps it to the external IP? I've also added the firewall rules (both 8888 and 8080) and I see they're mapped to the GCE instance.

Expected: Once I run 'docker run -d -p 8888:8888 ' from SSHing into the GCE instance, the app should be accessible by using the GCE instance's ExternalIP + port as well. Actual: Getting 'site can't be reached' in browser and an empty reply when using curl.

-- T Diddy
docker
google-cloud-platform
google-compute-engine
kubernetes

1 Answer

8/7/2019

I think that your docker command is wrong. It should be 'docker run -d -p 8888:8080 ' because the -p flag state that the first number is going to be the host port and the second the container port[1]. Per you curl command being successful, your container is listening in the 8080 port.

You application should now work with 'http://[external IP]:8888/healthCheck' or https, don't know if you are using SSL/TLS.

[1] https://docs.docker.com/engine/reference/run/#expose-incoming-ports

-- Luis Javier Alvarez Rodriguez
Source: StackOverflow