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 ?