Hello,
I have three Node.js containers running on ports 3000
, 3001
, and 3002
:
# docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
Admin yaml-admin "docker-entrypoint.s…" admin 20 minutes ago Up 20 minutes 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp
Contractor yaml-contractor "docker-entrypoint.s…" contractor 20 minutes ago Up 20 minutes 0.0.0.0:3001->3000/tcp, :::3001->3000/tcp
Nginx yaml-nginx "/docker-entrypoint.…" nginx 20 minutes ago Up 20 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
User yaml-user "docker-entrypoint.s…" user 20 minutes ago Up 20 minutes 0.0.0.0:3002->3000/tcp, :::3002->3000/tcp
Nginx configuration is as follows:
server {
server_name admin.myhost.comm;
error_log /var/log/nginx/error.admin.log;
access_log /var/log/nginx/access.admin.log;
location / {
proxy_pass http://admin:3000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
server {
server_name contractor.myhost.comm;
error_log /var/log/nginx/error.contractor.log;
access_log /var/log/nginx/access.contractor.log;
location / {
proxy_pass http://contractor:3001;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
server {
server_name user.myhost.comm;
error_log /var/log/nginx/error.user.log;
access_log /var/log/nginx/access.user.log;
location / {
proxy_pass http://user:3002;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
In the /etc/hosts file I added the following lines:
127.0.0.1 contractor.myhost.comm
127.0.0.1 admin.myhost.comm
127.0.0.1 user.myhost.comm
It works when I use the curl admin.myhost.comm
command, but curl contractor.myhost.comm
shows me the following error:
[error] 29#29: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 172.22.0.1, server: contractor.myhost.comm, request: "GET / HTTP/1.1", upstream: "http://172.22.0.5:3001/", host: "contractor.myhost.comm"
I can see all containers via the curl 127.0.0.1:PORT
command.
Why won’t only two containers work?
Thank you.