John Sorensen
John Sorensen

Reputation: 960

Google Cloud Firewall Exposing Port Docker

I managed to successfully deploy a docker image to a VM instance. How can I send network requests to it?

The code is a simple Node.js / express app that simply res.json() "Hi there!" on the root path. It is listening on port 3000.

I think the deploy process was this:

  1. Build Docker image from Node.js / express src.
  2. Run container on local command line, correctly expose ports. It works locally.
  3. Tagged the image with the correct project ID / zone.
  4. Pushed to VM. I Think I pushed the image, rather than the container. is this a problem?
  5. SSH into VM. Run docker ps and see running container with correct image tag
  6. use command line curl (I am using zsh terminal) as well as browser to check network requests. Getting connection refused error

As a beginner, the google firewall settings appear to be open--I have allowed ingress on all ports.

enter image description here

I will also want to allow egress at some point but for now my problem is that I am getting a connection refused error whenever I try to contact the IP address, either with my web-browser or curl from the command line.

It would seem that the issue is most likely with the firewalls, and I have confirmed that my docker container is running in the VM (and the source code works on my machine).

EDIT:

Updated Firewall Rules with Port 3000 Ingress:

enter image description here

Upvotes: 1

Views: 1303

Answers (2)

AnshelAtWork
AnshelAtWork

Reputation: 57

Just in case you hit this bump as well :>

  • I installed docker.io version 20.10 (default) on a Debian 11 GCP VM
  • I configure a Nginx docker and opened the FW

The docker Nginx was accessible from the host but not from the internet :(

  • I used tcpdump to verify the internet request traffic arrives on the host
  • At last I removed the docker.io 20.10 and installed docker 24.0.6

After the upgrade the Nginx docker was accessible from the internet :)

The only change i noticed after the upgrade is the additional port export: :::7070->80/tcp Extra port export

Upvotes: 1

DazWilkin
DazWilkin

Reputation: 40081

You need a firewall rule that permits traffic to tcp:3000.

Preferably from just your host's IP (Google "what's my IP?" And use that) but for now you can (temporarily) use any IP 0.0.0.0/0.

Firewall rules can be applied only to the VM running your container too, but I'd not worry about that initially.

Upvotes: 1

Related Questions