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:
Before diving into Nginx, make sure the core registry service is up and responding:
- Check if the container is active:
You should see thedocker psregistry:2container listed with a status ofUp X minutes/hours. - Test local connectivity directly to the registry port:
A successful response will returncurl http://127.0.0.1:5000/v2/{}— if you get an error here, the registry itself isn't working, so restart the container first withdocker restart registry.
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 0removes 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
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:
- Edit or create
/etc/docker/daemon.json:{ "insecure-registries": ["your-registry-domain.com:80"] } - Restart Docker to apply:
systemctl restart docker
For Windows/macOS (Docker Desktop):
- Open Docker Desktop settings → Go to Docker Engine
- Add the same
insecure-registriesentry to the JSON config - Click "Apply & Restart"
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
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




