前提條件:docker
知足以上條件時就能夠開始搭建了:安全
1. 生成用戶密碼文件:(運行下面命令後會在當前目錄的auth目錄下生成文件htpasswd,用戶名:bounter,密碼:111111)服務器
$ mkdir auth $ mkdir data $ docker run \ --entrypoint htpasswd \ registry:2 -Bbn bounter 111111 > auth/htpasswd
2. 當前目錄添加 docker-compose.yml,內容以下:(注意把掛載的路徑改爲你服務器的實際路徑)curl
registry: restart: always image: registry:2 ports: - 5000:5000 environment: REGISTRY_AUTH: htpasswd REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm volumes: - /home/simon/docker-registry/data:/var/lib/registry - /home/simon/docker-registry/auth:/auth
3. 啓動:docker-compose up -durl
4. 客戶端設置容許http不安全訪問私有倉庫:(vi /usr/lib/systemd/system/docker.service )spa
ExecStart=/usr/bin/dockerd --insecure-registry localhost:5000 systemctl daemon-reload systemctl restart docker
5. 操做私有倉庫(加上認證以後必須先登陸才能推送和拉取)rest
1)登陸:docker login localhost:5000code
2)推送:blog
docker tag openjdk:8 localhost:5000/openjdk:8docker-compose
docker push localhost:5000/openjdk:8
3)拉取:docker pull localhost:5000/openjdk:8
4)查看:curl --user bounter:111111 localhost:5000/v2/_catalog