第6章 建立容器的私有倉庫
阿新 • • 發佈:2020-12-06
倉庫是集中存放映象的地方。
註冊伺服器才是存放倉庫的具體的伺服器,每個伺服器上都存放著多個倉庫,而每個倉庫下放多個映象,每個映象上執行這多個容器,每個容器可以跑一個應用或者應用組。
倉庫的分類
倉庫分為公共倉庫和私有倉庫
- 最大的公共倉庫為hub.docker.com
- 一般公司都會用到私有倉庫
建立私有倉庫
- 安裝完docker後。可以通過官方提供的registry映象部署一套本地的私有倉庫環境
- -v 本地目錄:容器目錄
[root@localhost ~]# mkdir -p /opt/data/registry [root@localhost ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry Unable to find image 'registry:latest' locally latest: Pulling from library/registry cbdbe7a5bc2a: Pull complete 47112e65547d: Pull complete 46bcb632e506: Pull complete c1cc712bcecd: Pull complete 3db6272dcbfa: Pull complete Digest: sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d Status: Downloaded newer image for registry:latest WARNING: IPv4 forwarding is disabled. Networking will not work. 016adb8ddffb59e610d8a2867bd2b6952ce886b46e09d2306b4c265628a69543
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED
7ff804a476a0 registry "/entrypoint.sh /etc…" 27 hours
2cae978452d0 nginx "/docker-entrypoint.…" 27 hours - 將映象改名後推到倉庫中
-
docker tag nginx 192.168.2.222:5000/nginx:test 將映象改名 :原名 倉庫名:埠/映象
-
docker push 192.168.2.222:5000/nginx:test 將映象推到倉庫中
-
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED 7ff804a476a0 registry "/entrypoint.sh /etc…" 27 hours 2cae978452d0 nginx "/docker-entrypoint.…" 27 hours [root@localhost ~]#docker tag nginx 192.168.2.222:5000/nginx:test
[root@localhost ~]# docker push 192.168.2.222:5000/nginx:test
The push refers to repository [192.168.2.222:5000/nginx] Get https://192.168.2.222:5000/v2/: http: server gave HTTP response to HTTPS client -
推送失敗:原因docker預設是https提供服務,而這裡是HTTP
- 編輯/etc/docker/daemon.json
將地址加入,重新啟動docker,開啟倉庫 -
[root@localhost ~]# vim /etc/docker/daemon.json [root@localhost ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://72idtxd8.mirror.aliyuncs.com"],"insecure-registries": ["192.168.2.222:5000"] } [root@localhost ~]# systemctl restart docker [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2ec0654c9fd registry "/entrypoint.sh /etc…" 16 minutes ago Created cranky_shockley 7ff804a476a0 registry "/entrypoint.sh /etc…" 27 hours ago Exited (2) 2 minutes ago upbeat_ride 2cae978452d0 nginx "/docker-entrypoint.…" 27 hours ago Exited (0) 2 minutes ago nginx-1 [root@localhost ~]# docker start 7ff8 7ff8
- 重新將映象推送到倉庫
-
[root@localhost ~]# docker push 192.168.2.222:5000/nginx:test The push refers to repository [192.168.2.222:5000/nginx] 7e914612e366: Pushed f790aed835ee: Pushed 850c2400ea4d: Pushed 7ccabd267c9f: Pushed f5600c6330da: Pushed test: digest: sha256:99d0a53e3718cef59443558607d1e100b325d6a2b678cd2a48b05e5e22ffeb49 size: 1362
- 測試下載映象
-
[root@localhost ~]# docker rmi 192.168.2.222:5000/nginx:test Untagged: 192.168.2.222:5000/nginx:test Untagged: 192.168.2.222:5000/nginx@sha256:99d0a53e3718cef59443558607d1e100b325d6a2b678cd2a48b05e5e22ffeb49 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE [root@localhost ~]# docker pull 192.168.2.222:5000/nginx:test test: Pulling from nginx Digest: sha256:99d0a53e3718cef59443558607d1e100b325d6a2b678cd2a48b05e5e22ffeb49 Status: Downloaded newer image for 192.168.2.222:5000/nginx:test 192.168.2.222:5000/nginx:test [root@localhost ~]# docker images 192.168.2.222:5000/nginx test bc9a0695f571 11 days ago 133MB
-
- 停止容器之後,倉庫也關閉了,想要啟動容器就能夠直接執行倉庫加引數 --restart=always