You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Nginx反向代理Docker Registry后无法执行推送拉取操作求助

Hey there, let's work through your Docker Registry push/pull issues step by step. Based on the setup you described, here are the most likely fixes to get things working:

1. First, Confirm the Registry Container is Running Properly

Before diving into Nginx, make sure the core registry service is up and responding:

  • Check if the container is active:
    docker ps
    
    You should see the registry:2 container listed with a status of Up X minutes/hours.
  • Test local connectivity directly to the registry port:
    curl http://127.0.0.1:5000/v2/
    
    A successful response will return {} — if you get an error here, the registry itself isn't working, so restart the container first with docker restart registry.
2. Fix Your Incomplete Nginx Configuration

The snippet you shared is missing critical parts that Docker Registry requires to handle push/pull requests. Replace your myregistry.conf with this complete, tested configuration:

upstream docker_registry {
    server 127.0.0.1:5000;
}

map $upstream_http_docker_distribution_api_version $docker_distribution_api_version {
    '' 'registry/2.0';
}

server {
    listen 80;
    server_name your-registry-domain.com; # Replace with your actual domain or server IP

    location /v2/ {
        proxy_pass http://docker_registry;
        # Pass necessary headers to the registry
        proxy_set_header Host $http_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_set_header Docker-Distribution-Api-Version $docker_distribution_api_version;
        
        # Allow large image uploads (disable size limit)
        client_max_body_size 0;
        # Extend timeout to avoid interruptions during big pushes
        proxy_read_timeout 300s;
    }
}

Key fixes here:

  • The location /v2/ block ensures all Registry API requests are routed correctly
  • client_max_body_size 0 removes Nginx's default file size limit (critical for pushing large images)
  • Proper header forwarding lets the Registry validate and process requests correctly
  • Longer timeout prevents drops during lengthy uploads

After updating the config, reload Nginx to apply changes:

nginx -s reload
3. Let Docker Client Trust Your Insecure Registry

By default, Docker refuses to communicate with non-HTTPS registries. Since you're using port 80 (HTTP), you need to add your registry to Docker's allowed insecure list:

For Linux Clients:

  1. Edit or create /etc/docker/daemon.json:
    {
        "insecure-registries": ["your-registry-domain.com:80"]
    }
    
  2. Restart Docker to apply:
    systemctl restart docker
    

For Windows/macOS (Docker Desktop):

  1. Open Docker Desktop settings → Go to Docker Engine
  2. Add the same insecure-registries entry to the JSON config
  3. Click "Apply & Restart"
4. Use the Correct Image Tag Format

When pushing/pulling, you must tag your image with your registry's domain/IP and port:

  • Tag a local image for your registry:
    docker tag my-local-image:latest your-registry-domain.com:80/my-local-image:latest
    
  • Push it:
    docker push your-registry-domain.com:80/my-local-image:latest
    
  • Pull it from another machine:
    docker pull your-registry-domain.com:80/my-local-image:latest
    
5. Troubleshoot with Logs if Issues Persist

If things still aren't working, check the logs for clues:

  • Registry container logs:
    docker logs registry
    
  • Nginx access/error logs (usually in /var/log/nginx/):
    tail -f /var/log/nginx/error.log
    

Look for errors like 400 Bad Request (header issues) or 502 Bad Gateway (registry not reachable from Nginx).


内容的提问来源于stack exchange,提问作者Fernando Gonçalves

火山引擎 最新活动