安裝docker私有鏡像庫及簡易管理工具

安裝docker私有鏡像庫及簡易管理工具

1,使用compose文件拉起私有庫和簡易管理工具

  • compose文件如下:

version: '2'
services:
  registry:
    image: registry
    hostname: registry
    volumes:
      - "/usr/docker/registry/config.yml:/etc/docker/registry/config.yml"
      - "/opt/registry-var:/var/lib/registry"
    ports:
      - 5000:5000
    tty: true
    networks:
      app_net:

  registry-web: 
    image: hyper/docker-registry-web
    hostname: registryweb
    ports:
      - 8181:8080
    volumes:
      - "/usr/docker/registryweb/registryweb.yml:/conf/config.yml:ro"
    # environment:
    #   DOCKER_REGISTRY_URL: http://172.16.11.31:5000
    #   PUBLIC_REGISTRY_URL: http://172.16.11.31:5000
    #   ENABLE_DELETE_IMAGES: 'true'
    #   BASIC_AUTH_USER: 'admin'
    #   BASIC_AUTH_PASSWORD: 'password'
    tty: true
    networks:
      app_net:

networks:
  app_net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.20.0.0/16

注意:掛載的配置文件如下
私有庫的配置文件:


version: 0.1
log:
  fields:
    service: registry
storage:
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
  delete:
    enabled: true
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
    # Access-Control-Allow-Headers: ['*']
    # Access-Control-Allow-Origin: ['*']
    # Access-Control-Allow-Methods: ['GET,POST,PUT,DELETE']
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3

管理工具的配置文件:


registry:
  # Docker registry url
  url: http://172.16.11.31:5000/v2
  # Docker registry fqdn
  name: 172.16.11.31:5000
  # To allow image delete, should be false
  readonly: false
  auth:
    # Enable authentication
    enabled: false
    # Token issuer
    # should equals to auth.token.issuer of docker registry
    # issuer: 'my issuer'
    # Private key for token signing
    # certificate used on auth.token.rootcertbundle should signed by this key
    # key: /conf/auth.key

2,刪除鏡像

    在管理界面中只能邏輯刪除鏡像,並不能真正的釋放空間,需要執行私有庫的命令纔可以。
命令如下:那個ID是私有鏡像庫的容器ID
docker exec 2a8ece33062a bin/registry garbage-collect /etc/docker/registry/config.yml

把這個命令做成一個 *.sh 文件。

在linux的定時任務中把這個命令加進去。用到的命令如下:

systemctl list-units --type=service  #查看所有開機啓動的服務     

如果沒有啓動定時任務,用下面的命令,把釋放docker私有鏡像庫空間的命令加進去


systemctl start crontab  
systemctl enable crontab

crontab -e

0 */1 * * * /xx/xx.sh


crontab -l

0 */1 * * * /xx/xx.sh
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章