Forked from PieterScheffers/start_docker_registry.bash
Last active
August 26, 2018 09:25
-
-
Save jdk/eff5605c29584acab10cc65a837c49a3 to your computer and use it in GitHub Desktop.
Start docker registry with letsencrypt certificates (Linux Ubuntu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# install docker | |
# https://docs.docker.com/engine/installation/linux/ubuntulinux/ | |
# install docker-compose | |
# https://docs.docker.com/compose/install/ | |
# Make sure you have backports, add this to /etc/apt/source.list | |
# jesse-backports | |
# deb http://ftp.debian.org/debian jessie-backports main | |
# sudo apt-get update | |
# install letsencrypt | |
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04 | |
# https://letsencrypt.org/getting-started/ | |
# Generate SSL certificate for domain | |
/opt/letsencrypt/letsencrypt-auto certonly --keep-until-expiring --standalone -d domain.example.com --email info@example.com | |
# Setup letsencrypt certificates renewing | |
line="30 2 * * 1 /opt/letsencrypt/letsencrypt-auto renew >> /var/log/letsencrypt-renew.log" | |
(crontab -u root -l; echo "$line" ) | crontab -u root - | |
# Rename SSL certificates | |
# https://community.letsencrypt.org/t/how-to-get-crt-and-key-files-from-i-just-have-pem-files/7348 | |
cd /etc/letsencrypt/live/domain.example.com/ | |
cp privkey.pem domain.key | |
cat cert.pem chain.pem > domain.crt | |
chmod 777 domain.crt | |
chmod 777 domain.key | |
cd /root/ | |
mkdir auth | |
docker run \ | |
--entrypoint htpasswd \ | |
registry:2 -Bbn 'user' 'password' > auth/htpasswd | |
# https://docs.docker.com/registry/deploying/ | |
docker run -d \ | |
-p 5000: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 /etc/letsencrypt/live/domain.example.com:/certs \ | |
-v /opt/docker-registry:/var/lib/registry \ | |
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ | |
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ | |
registry:2 | |
# List images | |
# https://domain.example.com/v2/_catalog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment