Docker Compose Recipe

version: '2'

services:
  docker-registry:
    image: registry:2
    restart: always
    volumes:
      - ./data:/var/lib/registry
      - ./certs:/certs
      - ./auth:/auth
    env_file:
      - DOTENV/registry.env
    # ports:
    # - "5000:5000"

# create network: docker network create xnmp-network
networks:
  default:
    external:
      name: xnmp-network
File: /var/docker/registryhub/docker-compose.yml
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/fullchain.pem
REGISTRY_HTTP_TLS_KEY: /certs/privkey.pem
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
File: /var/docker/registryhub/DOTENV/registry.env
ToDo: add certificates in the ./cert/ folder
ToDo: add htpasswd in the ./auth/ folder
Research: How to use docker secrets without a swarm cluster

Generate htpasswd file

Head to this old site: https://mdstn.com/apps/textcrypt

For generating .htpasswd file for example:

  • Username: hello
  • Password: world
  • Path: /auth

Get here your .htpasswd

Run docker compose

docker-compose up -d
Run command from: /var/docker/registryhub/

Nginx Configuration

# docker.localhost
server {
	# listen 80;
	# listen [::]:80;
	server_name docker.localhost;
	return 301 https://$host$request_uri;
}

server {
    include /nginx/snippets/ssl-sylo-space.conf;
    server_name docker.localhost;
    resolver 127.0.0.11 valid=30s;
    set $upstream http://docker-registry:5000;
    include /nginx/snippets/snippet-server-location-upstream.conf;
    client_max_body_size 1000m;
}
File: docker.localhost.conf
Make sure you set client_max_body_size not too small or you’ll get 413 Request Entity Too Large.
For more information about this configuration, you can read my post below
Guide to install Nginx + Php + MariaDB + Phpmyadmin in Docker
Replace MAMP/XAMP with Docker Containers and keep you system clean.

Handy bash scripts

Docker Push

#!/bin/bash
REGISTRY_DOCKER_USERNAME=hello
REGISTRY_DOCKER_PASSWORD=world
REGISTRY_DOCKER_HUB=docker.localhost:5000
IMAGE=$1

docker login --username $REGISTRY_DOCKER_USERNAME --password $REGISTRY_DOCKER_PASSWORD $REGISTRY_DOCKER_HUB
docker tag $IMAGE $REGISTRY_DOCKER_HUB/$IMAGE
docker push $REGISTRY_DOCKER_HUB/$IMAGE
docker.push

How to run

docker.push harianto/mycontainer
Run commando anywhere
docker.push name/reference

Docker Pull

#!/bin/bash
REGISTRY_DOCKER_USERNAME=hello
REGISTRY_DOCKER_PASSWORD=world
REGISTRY_DOCKER_HUB=docker.localhost:5000
IMAGE=$1

docker login --username $REGISTRY_DOCKER_USERNAME --password $REGISTRY_DOCKER_PASSWORD $REGISTRY_DOCKER_HUB
docker pull $REGISTRY_DOCKER_HUB/$IMAGE
docker.pull

(Work in progress)