centos7系統下搭建docker本地鏡像倉庫

## 準備工做html

用到的工具, Xshell5, Xftp5, docker.io/registry:latest鏡像linux

關於docker的安裝和設置加速, 請參考這篇博文centos7系統下 docker 環境搭建docker

參考以前的博文, 設置完加速後, 執行docker pull registry命令, 下載docker.io/registry官方鏡像shell

## 啓動registry鏡像centos

啓動docker.io/registry容器, 若是tag是latest, 能夠忽略不寫微信

docker run -d -p 80:5000 --restart=always --name local_registry docker.io/registry:latest

-d 後臺運行
-p 端口映射, 宿主機80端口映射給容器的5000端口
--restart=always 容器意外關閉後, 自動重啓 (若是重啓docker服務, 帶這個參數的, 能自動啓動爲Up狀態, 不帶這個的,不會自動啓動)
--name 給容器起個名字, 能夠根據這個名字去中止/啓動/刪除容器ssh

## 配置端口開放curl

```
[root@localhost docker]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost docker]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  sourceports: 
  icmp-blocks: 
  rich rules: 
    
[root@localhost docker]# firewall-cmd --reload
success
[root@localhost docker]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh
  ports: 80/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  sourceports: 
  icmp-blocks: 
  rich rules: 
```

配置端口開放以後, 須要執行firewall-cmd --reload才能生效tcp

## 重命名鏡像工具

[root@localhost docker]# docker images
REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
repos_local/zookeeper                                0.0.1               bdb481b4f17a        2 days ago          541.5 MB

repos_local/zookeeper 是上篇博文介紹的使用Dockerfile文件建立的鏡像, 重命名

docker tag repos_local/zookeeper:0.0.1 192.168.199.131/repos_local/zookeeper:latest

docker tag 原鏡像名:tag 新鏡像名:tag

docker images 查看鏡像名稱是否更改正確

[root@localhost docker]# docker images
REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
192.168.199.131/repos_local/zookeeper                latest              bdb481b4f17a        2 days ago          541.5 MB

 

## 推送鏡像

docker push 192.168.199.131/repos_local/zookeeper:latest
若是提示如下錯誤, 說明沒有把搭建的registry加入可信任的列表裏面, 若是有https域名或者能建立.crt證書, 那麼能夠忽略如下步驟

Error response from daemon: invalid registry endpoint https://192.168.199.131/v0/: unable to ping registry endpoint https://192.168.199.131/v0/
v2 ping attempt failed with error: Get https://192.168.199.131/v2/: dial tcp 192.168.199.131:443: no route to host
 v1 ping attempt failed with error: Get https://192.168.199.131/v1/_ping: dial tcp 192.168.199.131:443: no route to host. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.199.131` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.199.131/ca.crt

解決方法:

只針對centos7下 Docker version 1.12.5, build 047e51b/1.12.5版本有效, 其它版本沒作過測試

vi /etc/sysconfig/docker

注意--insecure-registry 192.168.199.131插入的位置
# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --insecure-registry 192.168.199.131'
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi

重啓docker服務
systemctl restart docker.service

從新執行docker push 192.168.199.131/repos_local/zookeeper:latest , 此次應該就能成功了

## 查看鏡像倉庫

[root@localhost docker]# curl 192.168.199.131/v2/_catalog
{"repositories":["repos_local/zookeeper"]}
[root@localhost docker]# curl 192.168.199.131/v2/repos_local/zookeeper/tags/list
{"name":"repos_local/zookeeper","tags":["latest"]}

 

至於鏡像的刪除, 目前還沒找到一個好的解決方法, 若有建議請留言

 

 

 

 

如需幫助可向我發起QQ聊天發起QQ聊天

友情贊助

若是您喜歡此文,感受對您工做有幫助,預期領導會給您漲工資,不妨小額贊助一下,讓我有動力繼續努力。

贊助方式:打開支付寶App,使用「掃一掃」付款,付款碼見下圖,別忘了付款留言哦!


或使用微信, 不用加好友就能付款

相關文章
相關標籤/搜索