dockernginxdocker-registry

nginx in docker 502


I have a Docker Registry in a container on my server. My NginX is also in a container and another location(config) for static files works. So i can confirm that ssl is propperly configured. Curl on the server to the docker registry also works, so i can confirm that my registry is hosted correctly. (Linux reports it listening onto http://*:5000).

as far as i know i did everything right, but it somehow still doesnt work. here the 2 error messages i get:

2024/09/21 18:14:50 [error] 19#19: *34 no live upstreams while connecting to upstream, client: IP, server: docker.myDomain.org, request: "GET /v2/ HTTP/1.1", upstream: "http://localhost/v2/", host: "docker.myDomain.org"
2024/09/21 18:15:17 [error] 19#19: *35 connect() failed (111: Connection refused) while connecting to upstream, client: IP, server: docker.myDomain.org, request: "GET /.git/config HTTP/1.1", upstream: "http://127.0.0.1:5000/.git/config", host: "213.165.94.168"

my Config 'docker.conf' looks like:

server {
    listen 443 ssl;
    server_name docker.myDomain.org;

    ssl_certificate /etc/nginx/ssl/myDomain.org.cer;
    ssl_certificate_key /etc/nginx/ssl/myDomain.org.key;

    location / {
        # Do not allow connections from docker 1.5 and earlier
        # docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents
        if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
          return 404;
        }
        proxy_pass http://localhost:5000;
        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_read_timeout                  900;
    }

    access_log /var/log/nginx/docker-access.log;
    error_log /var/log/nginx/docker-error.log;
}

server {
    listen 80;
    server_name docker.myDomain.org;
    return 301 https://$host$request_uri;
}

what could be the issue here? (my tests currently are using postman and the browser); another private registy i use works with both my testing methods.

Since a have somewhat limited experience with nginx and issues finding informations on how to debug or troubleshoot such issues i hope for help here.


Solution

  • You are trying to proxy localhost

    In the context of the nginx container, localhost is the container itself.

    If you're using Docker Compose, you can simply use the container/service name http://servicename:5000

    If not, you'll need to create a network and add both containers to it