Hi together,
this is my first post here and iam quite new with Docker. If i have tagged something wrong please let me know. I hope you can help me with my approach, since i try over a week to get it work - without success:
Iam failing were i try to pass an proxy, which should direct the request to another docker, which (for testing purpose) just return “Hi from Docker”.
So my Linux Ubuntu does have this docker-compose.yml as starting point (works so far)
version: ‘3’
services:
proxy:
image: nginx:1
restart: always
ports:
- “80:80”
- “443:443”
volumes:
- ./conf.d:/etc/nginx/conf.d
- certs:/etc/letsencrypt
- certs-data:/data/letsencrypt
volumes:
certs:
certs-data:
The corresponding default.conf looks like this:
server {
listen 80;
server_name localhost;
location ^~ /.well-known {
allow all;
root /data/letsencrypt/;
}
}
So my problem now is here inside the api.conf:
server {
listen 80;
server_name myLinkToDomain;
location / {
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-Proto $scheme;
proxy_pass
http://dockerbuch-api-1.nginxterminator_default:3000; # THIS DOES NOT WORK
#http://dockerbuch-api-1.nginxterminator_default:80; # THIS WORKS!
proxy_read_timeout 90;
}
location ^~ /.well-known {
allow all;
root /data/letsencrypt/;
}
listen 443 ssl;
ssl_certificate
/etc/letsencrypt/live/myLinkToDomain/fullchain.pem;
ssl_certificate_key
/etc/letsencrypt/live/myLinkToDomain/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
if ($scheme != “https”) {
return 301 https://$host$request_uri;
}
}
So if i pass the proxy with :80, NGINX serves the standard HTML file. However, what i want instead is that its uses my docker image (name: “ten” in this case, which is listening to 3000)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77889c89ee56 ten “docker-entrypoint.s…” 12 minutes ago Up 12 minutes 5000/tcp, 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp
16eb1697e530 nginx “/docker-entrypoint.…” 11 hours ago Up 16 minutes 80/tcp dockerbuch-api-1
74dafc103304 nginx:1 “/docker-entrypoint.…” 11 hours ago Up 14 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
If i do:
curl localhost:3000 → Hi from Docker
curl 172.17.0.2:3000 → Hi from Docker.
Both cases works fine! If i add in proxy pass one of these:
#http://172.17.0.2:3000;
#http://127.0.0.1:3000;
# http://dockerbuch-api-1.nginxterminator_default:80 # THIS WORKS!
http://dockerbuch-api-1.nginxterminator_default:3000; # DOESNT WORK
It doesnt work . I get an 502 Bad Gateway from NGINX.
docker network ls gives me this:
NETWORK ID NAME DRIVER SCOPE
9b6544ca1449 bridge bridge local
5bedbafd7d95 dockerbuch_default bridge local
4222c070399e host host local
7130e05fe4c1 nginxterminator_default bridge local
035d77404a23 none null local
I believe the error needs to be somewere in wrong network conf:
I have set this also as an docker-compose.yml
(relates to this container: 16eb1697e530 nginx “/docker-entrypoint.…” 12 hours ago Up 25 minutes 80/tcp dockerbuch-api-1)
version: ‘3’
services:
api:
image: nginx
restart: always
networks:
- nginxterminator_default
- default
networks:
nginxterminator_default:
external: true
Iam quite desperate and would appreciate every help very very much. Best, Marc