The above answer is great! In addition, if you want to use this on a private repo, you need to add basic auth with your registry user credentials, and the additional scope parameter 'account='
(see http://www.cakesolutions.net/teamblogs/docker-registry-api-calls-as-an-authenticated-user)