Skip to content

Instantly share code, notes, and snippets.

@aduermael
Last active April 30, 2018 17:20
Show Gist options
  • Save aduermael/9d3946d66926056cf72b28a357ae6cf5 to your computer and use it in GitHub Desktop.
Save aduermael/9d3946d66926056cf72b28a357ae6cf5 to your computer and use it in GitHub Desktop.
Docker registry server with basic auth restricted access

How to deploy a registry server with basic auth restricted access

  • Create cert with Let's Encrypt
git clone https://github.com/letsencrypt/letsencrypt.git
cd letsencrypt
./letsencrypt-auto certonly
  • Prepare certificate bundle
cd /etc/letsencrypt/live/[domain] # <- replace [domain]
cat cert.pem chain.pem > domain.crt
cp privkey.pem domain.key
  • Generate password
mkdir auth
docker run --entrypoint htpasswd registry:2 -Bbn [user] [password] > auth/htpasswd
  • Run registry!
docker run -d -p 443:5000 --restart=always --name registry \
  -v `pwd`/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  -v `pwd`:/certs \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
  registry:2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment