Proxy

使用 S3 儲存桶和代理伺服器的本地容器系統資料庫

  • September 28, 2019

我正在嘗試在 AWS EC2 實例上部署本地 docker 系統資料庫。實例必須通過轉發代理 (apache) 伺服器進行訪問。但是,我無法從正在執行的系統資料庫容器實例中訪問 s3 儲存桶。我的 docker 系統資料庫實例配置如下:

version: '3'
services:
 localRegistry:
   image: registry:2
   ports:
     - "5000:5000"
   volumes:
     - ./auth:/auth
   environment:
     - "REGISTRY_AUTH=htpasswd"
     - "REGISTRY_AUTH_HTPASSWD_REALM=MyRealm"
     - "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd"
     - "REGISTRY_STORAGE=s3"
     - "REGISTRY_STORAGE_S3_REGION={{ s3Region }}"
     - "REGISTRY_STORAGE_S3_BUCKET={{ s3BucketName }}"
     - "REGISTRY_STORAGE_CACHE_BLOBDESCRIPTOR=inmemory"
     - "REGISTRY_STORAGE_S3_ACCESSKEY={{ s3UserAccessID }}"
     - "REGISTRY_STORAGE_S3_SECRETKEY={{ s3UserAccessKey }}"
     - "REGISTRY_STORAGE_S3_ROOTDIRECTORY=/registry"
     - "REGISTRY_MIDDLEWARE_REDIRECT_BASEURL={{ proxyServerURL }}"
   restart: always

我可以使用主機上的 AWS CLI 與使用者一起訪問 S3 儲存桶。我已在主機上禁用 SELinux。來自容器的錯誤消息是

localRegistry1  | time="2019-09-26T13:48:04.873569714Z" level=error msg="response completed with error" auth.user.name=<USER> err.code=unknown err.detail="s3aws: RequestError: send request failed
localRegistry1  | caused by: Put https://<s3BucketName>.s3.us-west-1.amazonaws.com/registry/docker/registry/v2/repositories/ubuntu/_uploads/34732c55-6be3-4741-bfa8-e084708eb2a1/startedat: dial tcp <s3BucketIP>:443: i/o timeout" err.message="unknown error" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=<requestID> http.request.method=POST http.request.remoteaddr="<docker0_iface_addr>:46102" http.request.uri="/v2/ubuntu/blobs/uploads/" http.request.useragent="docker/19.03.2 go/go1.12.8 git-commit/6a30dfc kernel/3.10.0-957.21.3.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/19.03.2 \(linux\))" http.response.contenttype="application/json; charset=utf-8" http.response.duration=2m0.357571388s http.response.status=500 http.response.written=104 vars.name=ubuntu 
localRegistry1  | <docker0_iface_addr> - - [26/Sep/2019:13:46:04 +0000] "POST /v2/ubuntu/blobs/uploads/ HTTP/1.1" 500 104 "" "docker/19.03.2 go/go1.12.8 git-commit/6a30dfc kernel/3.10.0-957.21.3.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/19.03.2 \\(linux\\))"

我認為這可能是轉發代理 ec2 伺服器和 docker 主機實例之間的 aws 安全組的問題。但是,我不太確定那會是什麼。

解決方案正盯著我的臉。將 HTTP(S)_PROXY 添加到容器環境變數中。

version: '3'
services:
 localRegistry:
   image: registry:2
   ports:
     - .....
   volumes:
     - .....
   environment:
     ......
     - "HTTP_PROXY={{ proxyServerURL }}"
     - "HTTPS_PROXY={{ proxyServerURL }}"
   restart: always

引用自:https://serverfault.com/questions/985744