安裝私人docker registry

環境準備

  • 安裝docker & docker compose
  • 建立一個目錄(如:backup)放置映像檔及設定檔
  • 設定環境變數:REGISTRY_STORAGE_DELETE_ENABLED=true
  • 掛載目錄:/backup/registry/images:/var/lib/registry、/mnt/shopee/backup/registry/config/config.yml:/etc/docker/registry/config.yml
  • 增加 人UI
registry-ui:
    image: konradkleine/docker-registry-frontend:v2
    container_name: registry-ui
    labels:
      - "PROJECT=registry"
    ports:
      - 3000:80
    networks:
      - docker-registry-network
    environment:
      - ENV_DOCKER_REGISTRY_PORT=5000
      - ENV_DOCKER_REGISTRY_HOST=registry
    depends_on:
      - registry
  • 啟動:docker-compose -f docker-compose.registry.yml up -d

完整設定擋

version: '3.7'
services:
  registry:
    image: registry:2
    container_name: docker-registry
    labels:
      - "PROJECT=registry"
    ports:
      - 5000:5000
    networks:
      - docker-registry-network
    environment:
      - REGISTRY_STORAGE_DELETE_ENABLED=true
    volumes:
      - "/mnt/shopee/backup/registry/images:/var/lib/registry"
      - "/mnt/shopee/backup/registry/config/config.yml:/etc/docker/registry/config.yml"
registry-ui:
    image: konradkleine/docker-registry-frontend:v2
    container_name: registry-ui
    labels:
      - "PROJECT=registry"
    ports:
      - 3000:80
    networks:
      - docker-registry-network
    environment:
      - ENV_DOCKER_REGISTRY_PORT=5000
      - ENV_DOCKER_REGISTRY_HOST=registry
    depends_on:
      - registry
networks:
  docker-registry-network:
    name: docker-registry-network
    labels:
      - "PROJECT=registry"

使用

  • Push & Pull image
# You could pull image from docker hub
$ docker pull redis:latest
# localhost:5000 is the registry link
# demo:redis -- just like docker hub name:tag
$ docker tags redis localhost:5000/demo:redis
# Push image to private registry
# Then you could see it from website
$ docker push localhost:5000/demo:redis
# Pull image from private registry
$ docker pull localhost:5000/demo:redis
  • 刪除映像檔
# Delete image need to get image's digest
$ curl -v localhost:5000/v2/demo/manifests/redis -H 'Accept: application/vnd.docker.distribution.manifest.v2+json'
# Then you will find a field name "Docker-Content-Digest:"
# Then use the digest value to the delete api
$ curl -X DELETE -v localhost:5000/v2/demo/manifests/sha256:8b5e24dd14cff03e0db8f372e6fd5a9a0f29af771122ef8e94917317db8c39f9