Hi,
I have a Docker Network with the following containers:
- app - ports “80:80”
- nginx_api - ports “81:80”
In app, there is an nginx listening to 80 and doing a proxy_pass to nginx_api:81 like this:
# app - nginx.con
http {
server {
location /api {
proxy_pass http://nginx_api:81/;
}
}
}
When I run the network and the containers and try to query, from a browser, the address http://dev.myproject.com/api/posts/, nginx from app replies with the following error (and nginx from nginx_api is not even reached):
[error] 6#0: *2 connect() failed (111: Connection refused) while connecting to upstream,
client: 172.18.0.1,
server: dev.myproject.com,
request: "GET /api/posts/ HTTP/1.1",
upstream: "http://172.18.0.2:81//posts/,
host: "localhost",
referrer: "http://localhost/"
However, when I directly query http://dev.myproject.com:81/posts/, the API responds accordingly (nginx_api works well).
Funny thing is, in the error message above, 172.18.0.2 is the correct address for nginx_api container (checked with docker network inspect).
I might be missing something here.
Important notes:
The two containers above are run with two different docker-compose.yml files, separately. The network they both belong to was created beforehand (docker network create my-network).
If I log into app container, I can ping nginx_api without any problem.
Any idea of how to make the proxy_pass to nginx_api:81 work in this configuration? Thanks!