Hi community,
in this helpful video here it is demonstrated how Nexus can be used as a private docker registry:
https://www.youtube.com/watch?v=Z2jH9LgeeI8I am wondering why you recommend to use different ports for pulling and pushing. I understand that it is necessary to forward the pull and push request to different Nexus Docker repositories. But instead of different ports I use this apache vhost configuration to split the traffic by the used http protocol method:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/ssl/certs/nexus.sprd.net.crt"
SSLCertificateKeyFile "/etc/ssl/private/nexus.sprd.net.key"
RewriteEngine on
#### pull ####
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^/(.*) /docker-pull/$1 [PT]
#### push ####
#HEAD checks if the layer is already in the private registry. I forward this to the push repo to make sure all layers are uploaded
#to this particular repo. Otherwise docker does reject pushing if some layers are missing (which are in fact in another nexus repos only and just merged by the repository group)
#forward snapshots
RewriteCond %{REQUEST_METHOD} (HEAD|POST|PATCH|PUT|DELETE)
RewriteCond %{REQUEST_URI} .*/snapshot/.*
RewriteRule ^/(.*) /docker-push-snapshot/$1 [PT]
#forward non-snapshots
RewriteCond %{REQUEST_METHOD} (HEAD|POST|PATCH|PUT|DELETE)
RewriteRule ^/(.*) /docker-push/$1 [PT]
## Proxy rules
ProxyRequests Off
ProxyPass /docker-pull
http://localhost:8083 <Location /docker-pull>
ProxyPassReverse
http://localhost:8083 </Location>
ProxyPass /docker-push
http://localhost:8082 <Location /docker-push>
ProxyPassReverse
http://localhost:8082 </Location>
ProxyPass /docker-push-snapshot
http://localhost:8085 <Location /docker-push-snapshot>
ProxyPassReverse
http://localhost:8085 </Location>
ServerName
myregistry.sprd.net ServerAdmin
ad...@example.com RequestHeader set X-Forwarded-Proto "https"
## Logging
ErrorLog "| /usr/bin/rotatelogs -l /var/log/apache2/registry-error.%Y.%m.%d 86400"
CustomLog "| /usr/bin/rotatelogs -l /var/log/apache2/registry-access.%Y.%m.%d 86400" combined
</VirtualHost>
Explanation of the ports:
- 8082 -> hosted repository with deployment policy: "Disable redeploy"
- 8085 -> hosted repository with deployment policy: "Allow redeploy"
- 8084 -> proxy repository for docker hub (only used via repository group)
- 8083 -> repository group which contains 1. docker-releases, 2. docker-snapshot and 3. docker-hub repos in that order
The ssl offloading is done by Apache2 not by Nexus
As you can see, only requests with GET method are forwarded to the repository group for read access. Requests which use the other listed methods are forwarded to the hosted release repository or snapshot repository, it depends if the word "snapshot" is part of the sent url. (The snapshot is only an internal convention, it reminds me to Maven snapshots...)
With this solution I can i.e. pull an image from docker-hub through Nexus
docker pull
myregistry.sprd.net/ubuntu:16.04I can also pull this image:
docker push
myregistry.sprd.net/ubuntu:16.04This one will end up in the release repository
If I use the word "snapshot" in my tag path i.e.
docker push
myregistry.sprd.net/snapshot/ubuntu:16.04this image and all related layers will be stored in my snapshot repository.
In my opinion this approach is much easier to handle then your suggestion with different ports.
I cannot believe that I am the only one who has the idea for this solution. Is there something I missed and could break later?
My tests are all successful so far. But also the guys from Artifactory recommend different ports for pulling and pushing:
https://www.youtube.com/watch?v=014ZXoJnDys&feature=youtu.be&list=PLY0Zjn5rFo4PR0MqN1MsqXG-t4izCcuUxSo, do you see any problems with my simplified approach? Please let me know!
Thank you in advance!
Regards,
Mario