I have a simple Node.js server application which I have containerized.
The Node.js server runs on port 3000 so it answers at URL http://localhost:3000.
In another application I have a docker-compose.yml file which pull the Node.js app image and run it, like this:
version: '3'
services:
myserver:
container_name: myserver_nodejs
image: registry.gitlab.com/cs-repos/work/myserver:v1.0.2-latest
ports:
- 3000:3000
It pulls the image from GitLab container registry, locally, and runs the container.
Issue:
In order to make a request to the server I need to add the port number like this: localhost:3000, then the path.
I wonder, is there a way so that the docker-compose.yml handles the port for me, so that I don't have to use it in my requests?
So to make a request like this: http://localhost/sales, and internally the request goes to port 3000.
Also i added a record in the /etc/hosts:
127.0.0.1 my.server.com.
Instead of using the localhost, I can use the mapped address my.server.com but I need the port number at the end as well.
The ports property just makes a mapping between the host and the container, it is needed but it's not solving the issue:
ports:
- 3000:3000