docker save <鏡像名> | bzip2 | pv | ssh <用戶名>@<主機名> 'cat |docker load'
容器快照文件將丟失全部的歷史數據和元數據信息(僅保存容器當時的快照狀態) 從容器快照文件導入時能夠從新指定標籤等元數據信息。 鏡像存儲文件則將保存完整記錄, 體積也要更大。
docker container prune
命令行登錄 退出mysql
docker login docker logout
查找 拉取鏡像nginx
docker search docker pull
推送鏡像git
用戶在登錄後 docker push 將本身的鏡像推送到Docker Hub
自動建立sql
容器運行docker
docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry
在私有倉庫上傳、搜索、下載鏡像json
docker tag 標記一個鏡像,並推送到倉庫。好比私有倉庫地址爲127.0.0.1:5000ubuntu
格式: docker tag IMAGE[:TAG] [REGISTRY_HOST][:REGISTRY_PORT/]REPOSITORY[:TAG]
docker tag docker.io/mysql:5 127.0.0.1:5000/docker.io/mysql:5
docker push 上傳標記的鏡像centos
docker push 127.0.0.1:5000/docker.io/mysql
curl 查看倉庫中的鏡像服務器
curl 127.0.0.1:5000/v2/_catalog
從私有倉庫下載dom
須要先刪除已有鏡像 docker image rm 127.0.0.1:5000/docker.io/mysql:5 docker pull 127.0.0.1:5000/docker.io/mysql:5
注意事項
Docker默認不容許非HTTPS方式推送鏡像,能夠經過docker配置選項取消這個限制
對於upstar系統(Ubuntu 14.04 Debian7 Wheezy)
編輯/etc/default/docker,在其中的DOCKER_OPTS增長內容 DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com --insecure-registries=10.9.2.100:5000" sudo service docker restart
對於systemd系統(Ubuntu16.04+ Debian8+ centos7)
編輯/etc/docker/daemon.json (不存在則新建) { "registry-mirror": [ "https://registry.docker-cn.com" ], "insecure-registries": [ "122.112.207.157:5000" ] } systemctl restart docker
使用Docker Compose構建,搭建一個擁有權限認證、TLS的私有倉庫
使用openssl自行簽發docker.domain.com的站點的SSL證書
step1 建立 CA 密鑰
openssl genrsa -out "root-ca.key" 4096
step2 利用私鑰建立 CA 根證書請求文件
openssl req \ -new -key "root-ca.key" \ -out "root-ca.csr" -sha256 \ -subj '/C=CN/ST=Zhejiang/L=Hangzhou/O=eichong/CN=eichong Docker Registry CA'
-subj參數 /C 表示國家 如CN /ST 表示省 /L 表示城市或地區 /O 表示組織名 /CN 通用名稱
step3 配置 CA 根證書,新建root-ca.cnf
[root_ca] basicConstraints = critical, CA:TRUE, pathlen:1 keyUsage = critical, nonRepudiation, cRLSign, keyCertSign subjectKeyIdentifier=hash
step4 簽發根證書
openssl x509 -req -days 3650 -in "root-ca.csr" \ -signkey "root-ca.key" -sha256 -out "root-ca.crt" \ -extfile "root-ca.cnf" -extensions \ root_ca
step5 生成站點 SSL 私鑰
openssl genrsa -out "docker.domain.com.key" 4096
step6 使用私鑰生成證書請求文件
openssl req -new -key "docker.domain.com.key" -out "site.csr" -sha256 \ -subj '/C=CN/ST=Zhejiang/L=Hangzhou/O=eichong/CN=docker.domain.com'
step7 配置證書,新建 site.cnf 文件
[server] authorityKeyIdentifier=keyid, issuer basicConstraints = critical, CA:FALSE extendedKeyUsage=serverAuth keyUsage = critical, digitalSignature, keyEncipherment subjectAltName = DNS:docker.domain.com, IP:127.0.0.1 subjectKeyIdentifier=hash
step8 簽署站點 SSL 證書
openssl x509 -req -days 750 -in "site.csr" -sha256 \ -CA "root-ca.crt" -CAkey "root-ca.key" -CAcreateserial \ -out "docker.domain.com.crt" -extfile "site.cnf" -extensions server
通過以上步驟,就擁有了docker.domain.com的網站SSL私鑰 docker.domain.com.key 和 SSL證書 docker.domain.com.crt 新建ssl文件夾將 docker.domain.com.key docker.domain.com.crt 移入,其餘刪除
配置私有倉庫
私有倉庫默認的配置文件位於 /etc/docker/registry/config.yml ,咱們先在本地編輯 config.yml ,以後掛載到容器中。
version: 0.1 log: accesslog: disabled: true level: debug formatter: text fields: service: registry environment: staging storage: delete: enabled: true cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry auth: htpasswd: realm: basic-realm path: /etc/docker/registry/auth/nginx.htpasswd http: addr: :443 host: https://docker.domain.com headers: X-Content-Type-Options: [nosniff] http2: disabled: false tls: certificate: /etc/docker/registry/ssl/docker.domain.com.crt key: /etc/docker/registry/ssl/docker.domain.com.key health: storagedriver: enabled: true interval: 10s threshold: 3
生成 http 認證文件
mkdir auth docker run --rm \ --entrypoint htpasswd registry \ -Bbn username password > auth/nginx.htpasswd
version: '3' services: registry: image: registry ports: - "443:443" volumes: - ./:/etc/docker/registry - registry-data:/var/lib/registry volumes: registry-data:
修改 hosts
編輯 /etc/hosts
docker.domain.com 127.0.0.1
啓動
docker-compose up -d
測試私有倉庫功能
登陸到私有倉庫
docker login docker.domain.com
嘗試推送、拉取鏡像
docker pull ubuntu:17.10 docker tag ubuntu:17.10 docker.domain.com/username/ubuntu:17.10 docker push docker.domain.com/username/ubuntu:17.10 docker image rm docker.domain.com/username/ubuntu:17.10 docker pull docker.domain.com/username/ubuntu:17.10