Your own image registry

Installation

Create directories:

/var/docker/registry/registry
/var/docker/registry/certs
/var/docker/registry/auth

Receive certificate with certbot or buy it. Save certificate to /var/docker/registry/certs/.

Get random string cat /dev/urandom | tr -dc ‘a-zA-Z0-9’ | head -c 32

Run in auth directory: htpasswd -Bbn username my_password > htpasswd

docker-compose.yml:

registry:
  container_name: registry
  restart: always
  image: registry:latest
  ports:
    - 5001:5000
  environment:
    REGISTRY_HTTP_TLS_CERTIFICATE: /certs/fullchain1.pem
    REGISTRY_HTTP_TLS_KEY: /certs/privkey1.pem
    REGISTRY_AUTH: htpasswd
    REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
    REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
    REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
    REGISTRY_HTTP_SECRET: <insert random string here>
  volumes:
    - /var/docker/registry/registry:/var/lib/registry
    - /var/docker/registry/certs:/certs
    - /var/docker/registry/auth:/auth

Now you can run it: docker-compose up -d

And login: docker login localhost:5001

More https://libertyseeds.ca/2015/10/05/Set-up-a-private-Docker-registry/

Using

Console commands:

#pull from registry to local cache
docker pull ubuntu:16.04
docker pull localhost:5000/my-ubuntu

#push builded or pulled image
docker tag ubuntu:16.04 localhost:5000/my-ubuntu
docker push localhost:5000/my-ubuntu

#remove locally cached
docker image remove ubuntu:16.04
docker image remove localhost:5000/my-ubuntu