Press "Enter" to skip to content

Nginx Proxy Manager代理 docker hub

前提

在非大陆服务器安装,以下域名仅作演示,不可实际使用

安装 docker

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker

安装 docker-compose

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

安装Nginx Proxy Manager

docker-compose.yml

version: '3.8'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
docker-compose up -d

访问管理面板

http://ip:81

默认登录账号密码

Email:    admin@example.com
Password: changeme

配置反向代理

进入proxy hosts

添加proxy host

添加域名,其他必选项(*)按图填写

然后切换到 ssl

按图修改,这里是为了给域名申请免费权威域名证书,所以在配置前先把域名 a 记录到服务器公网 ip

切换到 advanced

配置自定义 location

location 内容

        location / {
                    # Docker hub 的官方镜像仓库
                    proxy_pass https://registry-1.docker.io;  
                    proxy_set_header Host registry-1.docker.io;
                    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_buffering off;
                    # 转发认证相关
                    proxy_set_header Authorization $http_authorization;
                    proxy_pass_header  Authorization;
                    # 对 upstream 状态码检查,实现 error_page 错误重定向
                    proxy_intercept_errors on;
                    recursive_error_pages on;
                    # 根据状态码执行对应操作,以下为381、302、387状态码都会触发
                    error_page 301 302 307 = @handle_redirect;
        }
        location @handle_redirect {
                    resolver 1.1.1.1;
                    set $saved_redirect_location '$upstream_http_location';
                    proxy_pass $saved_redirect_location;
        }

最后保存后就大功告成了,然后可以测试下效果

docker pull docker.chenjie.info/library/golang:1.20.4
1.20.4: Pulling from library/golang
bd73737482dd: Downloading  9.191MB/55.05MB
6710592d62aa: Downloading  9.994MB/15.76MB
75256935197e: Downloading  9.191MB/54.58MB
948a624948ba: Waiting 
147e02c24f40: Waiting 
cd56b3199c0c: Waiting 

配置 docker 加速


vim /etc/docker/daemon.json

{
    "registry-mirrors": [
        "https://docker.chenjie.info"
    ],
}

然后重启 docker

systemctl restart docker

配置 containerd 加速

vim /etc/containerd/config.toml

[plugins.cri.registry]
[plugins.cri.registry.mirrors]
[plugins.cri.registry.mirrors."docker.io"]
endpoint = ["https://docker.chenjie.info"]

然后重启containerd

systemctl restart containerd

参考

  1. https://www.cnblogs.com/guangdelw/p/18253540
  2. https://cloud.tencent.com/document/product/457/51237
  3. https://nginxproxymanager.com/guide/#quick-setup
发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据