仓库是集中存放镜像的地方。
注册服务器才是存放仓库的具体的服务器,每个服务器上都存放着多个仓库,而每个仓库下放多个镜像,每个镜像上运行这多个容器,每个容器可以跑一个应用或者应用组。
仓库的分类
仓库分为公共仓库和私有仓库
- 最大的公共仓库为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