歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS 7 Docker 搭建私有倉庫 registry

CentOS 7 Docker 搭建私有倉庫 registry

日期:2017/2/28 13:57:03   编辑:Linux教程

環境規劃:

  • docker私有倉庫地址:192.168.0.167
  • docker客戶端地址 : 192.168.0.167

·關閉防火牆和selinux

systemctl stop firewalld.service
systemctl disable firewalld.service

# vi /etc/sysconfig/selinux
SELINUX=disabled
# setenforce 0

服務端

1.安裝並啟動docker

yum -y install docker
service docker start
chkconfig docker on

2.拉取本地私有倉庫registry

[root@localhost ~]# docker pull registry
Trying to pull repository docker.io/registry ...
24dd746e9b9f: Download complete
706766fe1019: Download complete
a62a42e77c9c: Download complete
2c014f14d3d9: Download complete
b7cf8f0d9e82: Download complete
d0b170ebeeab: Download complete
171efc310edf: Download complete
522ed614b07a: Download complete
605ed9113b86: Download complete
22b93b23ebb9: Download complete
2ac557a88fda: Download complete
1f3b4c532640: Download complete
27ebaac643a7: Download complete
ce630195cb45: Download complete
Status: Downloaded newer image for docker.io/registry:latest

3.查看registry鏡像

[root@localhost ~]# docker images
docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/CentOS latest ce20c473cd8a 6 days ago 172.3 MB

4.基於私有倉庫鏡像運行容器

默認情況下,會將倉庫存放於容器的/tmp/registry目錄下,這樣如果容器被刪除,則存放於容器中的鏡像也會丟失,所以我們一般情況下會指定本地一個目錄掛載到容器的/tmp/registry下, 兩個目錄下都有!

·registry的默認存儲路徑是/tmp/registry,只是個臨時目錄,一段時間之後就會消失

·所以使用-v參數,指定個本地持久的路徑,

[root@localhost ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
bb2c0d442df94e281479332c2608ef144f378e71743c5410e36b80c465771a95
root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb2c0d442df9 docker.io/registry:latest "docker-registry" 10 seconds ago Up 7 seconds

5.訪問私有倉庫

[root@localhost ~]# curl 127.0.0.1:5000/v1/search
{"num_results": 0, "query": "", "results": []} #私有倉庫為空,沒有提交新鏡像到倉庫中

6.從Docker HUB 上拉取一個鏡像測試

[root@localhost ~]#docker pull busybox
[root@localhost ~]#docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB

7.創建鏡像鏈接為基礎鏡像打個標簽

[root@localhost ~]# docker tag docker.io/busybox 192.168.0.167:5000/busybox
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.0.167:5000/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB

8.修改docker配置文件,指定私有倉庫url

[root@localhost ~]# vim /etc/sysconfig/docker
修改此行
OPTIONS='--insecure-registry 192.168.0.167:5000 '
[root@localhost ~]# service docker restart

9.上傳鏡像到本地私有倉庫

docker push 192.168.0.167:5000/busybox

10.查看私有倉庫是否有對應的鏡像

[root@localhost ~]# curl 192.168.0.167:5000/v1/search
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/busybox"}]}

11.查看鏡像的存儲目錄和文件

[root@localhost ~]# tree /opt/data/registry/repositories/
/opt/data/registry/repositories/
└── library
└── ssh
├── _index_images
├── json
├── tag_latest
└── taglatest_json

2 directories, 4 files

客戶端

1.安裝並啟動docker

yum -y install docker
service docker start
chkconfig docker on

2.修改docker配置文件,指定私有倉庫url

[root@localhost ~]# vim /etc/sysconfig/docker
修改此行
OPTIONS='--insecure-registry 192.168.0.167:5000 '
[root@localhost ~]# service docker restart

3.測試,下載剛才上傳的鏡像

[root@localhost ~]# docker pull 192.168.0.167:5000/busybox
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
192.168.0.167:5000/busybox latest 0064fda8c45d 5 days ago 1.113 MB
docker.io/registry latest 105c6c9299d9 5 days ago 423.3 MB
docker.io/centos latest ce20c473cd8a 6 days ago 172.3 MB
docker.io/atcol/docker-registry-ui latest d838355ad903 6 months ago 890.5 MB

Copyright © Linux教程網 All Rights Reserved