什么是X-Registry-Auth的内容推送到私人registry

当使用REST API将Docker镜像推送到私有registry时,X-Registry-Auth头文件的内容应该是什么? 根据使用Docker API推送到私有registry ,需要X-Registry-Auth头。 https://groups.google.com/forum/#!topic/docker-user/vXcA8fsCNZMbuild议该值应该是以下forms的base64编码的JSONstring:

{'username': string, 'password': string, 'email': string, 'serveraddress' : string} 

在设置了合适的环境variables之后,我做了:

 XRA=`echo "{\"username\": \"${USERNAME}\", \"password\": \"${PASSWORD}\", \"email\": \"${EMAIL_ADDRESS}\", \"serveraddress\" : \"${SERVER_ADDRESS}\"}" | base64 --wrap=0` curl -v --request POST --header "X-Registry-Auth: $XRA" http://$DOCKER_HOST/v1/images/$REGISTRY/$NAMESPACE/$REPOSITORY?tag=$TAG 

并得到一个403 Forbidden回应。

也许问题只是我不知道价值应该是什么。 我怎样才能确定他们? Docker似乎有办法; sudo docker push $REGISTRY/$NAMESPACE/$REPOSITORY:$TAG工作得很好。

我认为你的编码中缺less两层。 生成头的实际代码(来自github )

 def encode_header(auth): auth_json = json.dumps(auth).encode('ascii') return base64.b64encode(auth_json) def encode_full_header(auth): """ Returns the given auth block encoded for the X-Registry-Config header. """ return encode_header({'configs': auth}) 

所以你需要一个{'configs'的外部映射:[auth entries的数组}},所有json-then-base64编码。

检查你的身份validation环境variables的问题

 docker login --username $USERNAME --password $PASSWORD --email $EMAIL_ADDRESS $SERVER_ADDRESS 

如果他们是正确的,你会看到“login成功”。

我怀疑$ NAMESPACE应该匹配$ USERNAME。 尝试使用v1.13作为版本而不是v1。

我有一个私人nexusdocker回购(Docker Api v2),对我来说,这是解决scheme:

  XRA=`echo "{ \"username\": \"yourname\", \"password\": \"yourpass\", \"email\": \"youmail@example.org\" }" | base64 --wrap=0` curl -X POST -d "" -H "X-Registry-Auth: $XRA" http://localhost:4243/images/create?fromImage=private.host:19003/imagename&tag=latest