Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping ports in Compute Engine with Docker

I have a docker image running on Google Compute Engine. The image contains a Spring Boot application running on port 9000.

It is exposes on http://<ip>:9000 and I can access is without any problems. I am trying to configure the exposed port to be 80 in order to configure DNS record to point just to the IP address.

My question is how to achieve that because the documentation left me confused. I am using the online GCP console (web interface) for the deployment and there is no field to specify docker run -p 9000:80 command which would solve my issue (if there is, please correct me).

So do I need to remap the port in the Spring Boot settings? Or inside the Docker container? Or am I suppose to configure some forwarding rules in GCP? Thanks for the clarification!

My DOCKER file looks as follows:

FROM gcr.io/distroless/java
VOLUME /tmp
ADD build/libs/*.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT ["java","-jar","app.jar"]

I am using the Container optimized OS from GCP.

like image 890
Smajl Avatar asked Nov 17 '22 03:11

Smajl


1 Answers

tldr : you can't

When you deploy a container in compute engine in this way, docker network is in host network mode, which means that (doc) : a container shares the host's network stack and all interfaces from the host are available to the container.

So compute engine will directly expose container port, on his own interface. So you have to configure your container to expose correct port.

like image 152
Antoine Avatar answered Dec 15 '22 05:12

Antoine