Hello everyone, I am running command docker pull docker.io/mysql:8.0.40-debian . but in my country, I can not access docker.io. so I want to redirect docker.io to https://swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io
This is my /etc/nginx/sites-available/gwf-container
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1 localhost
127.0.1.1 DOOR. DOOR
127.0.1.1 gcr.io registry.k8s.io docker.io registry-1.docker.io
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
According to the documentation, if you set a URI in the proxy_pass directive, is replaces the URI from the original request Module ngx_http_proxy_module.
In your case, you have this directive: proxy_pass https://swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io;
Note that you have a URI specified in your proxy_pass directive parameter. This means that requests such as
GET /mysql:8.0.40-debian HTTP/1.1
...
Will just be passed to the backend server as
GET /ddn-k8s/docker.io HTTP/1.1
...
Which might explain why docker cannot find your image.
I suppose you want instead to make requests to the backend server with the following URI:
GET /ddn-k8s/docker.io/mysql:8.0.40-debian HTTP/1.1
...
If this is the case, you may replace your: proxy_pass https://swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io;
This will append the original request’s URI to your /ddn-k8s/docker.io prefix before passing the request to the backend server.
Here is another discussion that may help in that topic How to proxy the full url at nginx config? - Server Fault
Could you test and tell us if it solves the issue?
I believe that by default docker is going to use HTTPS pull images, so that might be part of the problem. Is there anything in the access.log? You should be able to see some more information about what requests NGINX is seeing from these calls.
As a side note, is there a reason you don’t just want to pull directly from the docker registry you are attempting to proxy with NGINX? This could be an issue with the docker client attempting to block what it could see as a “man in the middle” attack.