Self-hosted docker registry on Debian

Installation

  • Docker
  • Caddy web server as reverse proxy

Docker daemon

You will get a personal registry with basic auth and store registry on your local machine.

# Make directory

mkdir ~/docker_registry

# Go inside docker_registry directory
cd ~/docker_registry

# Setup basic auth

mkdir auth/

docker run \
   --entrypoint htpasswd \
   httpd:2 -Bbn username password > auth/htpasswd

# Run registry daemon

docker run -d \
  -v "$(pwd)"/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  -p 5000:5000 --restart always \
  --name registry -v /root/docker_registry:/var/lib/registry \
  registry:latest

Caddy configuration

# Caddy config

nano /etc/caddy/Caddyfile

# Paste into your config
{
 auto_https disable_redirects
}

# Docker registry
https://hub.xxx.xxxx:443 {
  reverse_proxy http://localhost:5000
}

Client do docker login

docker login hub.xxx.xxx

Docker push image to your private registry

# Docker tag local image
docker tag busybox hub.xxx.xxx/username/busybox

# OR
# Docker commit your custom build image
docker commit 6c664ed7afbb hub.xxx.xxx/username/busybox

# Finally push to your private registry
docker push hub.xxx.xxx/username/busybox

Photos credit: https://unsplash.com/photos/1gLdTsX3_70

References:
1. https://docs.docker.com/registry/deploying/#native-basic-auth