Docker communication within VPS (ERR_NAME_NOT_RESOLVED)

I am developping a webapp project and started hosting it online. I got a domain name and a VPS from OVH. I run 2 docker containers within my VPS (front and back).

When I’m connected to my front through my domain name and trying to make any call to the back end, I end up getting ERR_NAME_NOT_RESOLVED errors.

Both docker containers are up and on the same network

[
    {
        "Name": "custom_net",
        "Id": "c4cb2d130ec50ebc383b383eb46e6ea8eef43e8564d9d7e144ee217064dbb48e",
        "Created": "2023-08-24T10:14:24.929617144Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ef1b1022ba515532688326955bbc04e3db02ae26808ebdd3bef4ac8ef6d76e91": {
                "Name": "blindtest-back",
                "EndpointID": "9b67ed7c930948068f3e560ef43d96328c3fda31dee01c8ad5b1014b72c7d28c",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            },
            "f13e26948ae720e06b1d5666e8289bdf68bbc8c99aee99d74f5a861659f839ff": {
                "Name": "blindtest-front",
                "EndpointID": "c390a890f58905af1360b2c2d3bd0f6e6a85f9d5c59cd42071de46f40564ece9",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Here is the docker-compose

version: '3'
services:
  blindtest-front:
    build:
      context: blindtest-front
    container_name: blindtest-front
    ports:
      - "80:80"
    networks:
      - custom_net

  blindtest-back:
    build:
      context: blindtest-back
    container_name: blindtest-back
    ports:
      - "8000:8000"
    networks:
      - custom_net

networks:
  custom_net:
    name: custom_net
    driver: bridge

If I get into the front container via docker exec -it, I can ping my back-end container but curl doesn’t work.

From what I understood searching online, this is because my browser is trying to access the backend api via http://blindtest-back:8000/api/whatever but he doesn’t know, only my front end container knows but the request is made from the client browser.

But I cannot find a way to make this work, should I implement a proxy to do redirection ?

We can’t know whether your frontend service just serves a page, and the browser on your client machine calls the backend using javascript, or your frontend service just receives parameters through get parameters or post parameter through forms, then queries the backend itself, and renders the response, which it then serves back to the client. This is something you should know :slight_smile:

Depending on the solution the process that accesses the backend, either is located in your client brower, or in the frontend container. While the first needs the public domain name to reach the backend, the 2nd could either use the container name blindtest-back or the public domain name.

Can you extend on why you believe a proxy would solve that particular issue in your situation?

Thank you for answering

My front-end service query the back-end through GET and POST with parameters from forms. It also connects to a websocket.

Depending on the solution the process that accesses the backend, either is located in your client brower, or in the frontend container. While the first needs the public domain name to reach the backend, the 2nd could either use the container name blindtest-back or the public domain name.

If I get this part well, then I should expose my back-end services to everyone by opening a DNS route between the domain name and my VPS back-end container ?

Can you extend on why you believe a proxy would solve that particular issue in your situation?

I’ve seen people talking about reverse proxy using nginx to redirect routes to the correct container, since they’re both using the same domain name but just different port.

It doesn’t hurt to put both services behind a reverse proxy and use path bases routing to reach the target container. Though, it is not the solution for the problem you are experiencing.

I am not entirely sure what you try to say, but since you already must hava public domain to access the frontend service, you already have a dns entry that resolves to your vps host.

It seems like you missed the most relevant part: your frontend serves a page and javascript that uses the wrong URL (=container name instead of public dns name) for the backend service. You need to fix this in your frontend code. This is nothing I can help you with.

Update: I thought I miss-read. The process that access the backed service is running inside the browser, not in your fronted service. I reverted the temporary response back to my original response.

1 Like

It seems like you missed the most relevant part: your frontend serves a page and javascript that uses the wrong URL (=container name instead of public dns name) for the backend service. You need to fix this in your frontend code. This is nothing I can help you with.

Ok so my frontend should just call http://my_domain_name/api/whatever ?
When I’m trying this from my browser, I get a 404 from nginx so I suppose I’m missing some nginx conf there ?

Sorry about all my confusion and questions, I’m new to hosting and all seems a bit blurry. Thank you again for your time and your explanations

If you set up a reverse proxy. Yes. Without reverse proxy http://my_domain_name:8080/api/whatever.

Just to be sure: my_domain_name is an entry in the dns server where you manage your domain. This is nothing docker is involved in.

1 Like

Ok thank you, will try to make all of this work