Problem with server-client routing in docker

Hello all,

I am running a server-client application within a container. The server runs on port 8080 and the client runs on port 3000.

I have mapped my docker ports like this -p 3000:3000 -p 8080:8080 and I run the client on hostname so that it is exposed to the internet.

The reason to the port mapping 3000:3000 is that users are supposed to go to website:3000 and then get routed in to the docker to fetch the client in to the browser.

The reason for the port mapping of 8080:8080 is that I load data in to the server through another client on the host.

What IS working is that it is possible to go to website:3000 and render the client, and access the file system in the container. I can curl the client and the server from the host and within the container. I can load data into the server from the host.

What is NOT working is the communication between the client and the server within the container. Some data that is supposed to load in the browser cannot be retrieved.

When I look in the network tab the origin of the fetch is website:3000 and the request url is serverlurl:8080.

What I believe the problem is, since I have mapped any communication from port 3000 on the host, should be mapped to port 3000 in the container, something wrong happens since the browser makes a request to port 8080.

I am not sure how to map this. The workflow I am imagining is …

(Host (Browser:3000) → Container(client:3000 → (server:8080)))

I just started to learn docker 2-3 days ago so I am quite confused on how everything operates so appreciate any help!

Can you try to put it in different words?

Are client:3000 and server:8080 realy running in the same container?
Is client:3000 just static content that delivers a webapp to the browser which accesses server:8080 itself OR is client:3000 a backend application that interacts itself with server:8080 without the client beeing involved?

Thank you for your answer!

Yes, I have started both the client and the server from within the same container. I have also checked with ps aux that there are indeed processes running in the container.

Good question, I believe it must be the first case, the browser fetches the static content on 3000, and then a user can interact with it to fetch data from the server on 8080.

Maybe I should create another mapping on 3000:8080 or would this cause a clash with the 3000:3000 mapping?

This is not possible, as the left hand side of a port mapping is the host port - a port can only be bound once on a host.

My usual process is “see → assess → act” and so far I feel the level of shared details does not allow to assess anything. Please share more information about what you think is relevant for another person to know to understand your scenario.

Found the issue! The requests issued from the client was expecting to find the server on localhost:8080, changing this to website:8080 and keeping the port mapping 8080:8080 routed the requests correctly into the server within the container :slight_smile: