1、下载registry 镜像,registy为docker官方提供的一个镜像,我们可以用它来创建本地的docker私有仓库。
[root@localhost ~]# docker pull registry
Using default tag: latest
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
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 2d4f4b5309b1 4 months ago 26.2 MB
2、以registry镜像启动容器,-p会把容器的端口映射到宿主机上,:左边为宿主机监听端口,:右边为容器监听端口
[root@localhost ~]# docker run -itd -p 5000:5000 registry
1eb165757b68c44000cc64d1f60ca455a138da36d81cc8734e1d24fe325b7036
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1eb165757b68 registry "/entrypoint.sh /e..." 9 seconds ago Up 9 seconds 0.0.0.0:5000->5000/tcp nifty_shaw
[root@localhost ~]#
[root@localhost ~]# docker run -itd -p 5000:5000 registry
1eb165757b68c44000cc64d1f60ca455a138da36d81cc8734e1d24fe325b7036
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1eb165757b68 registry "/entrypoint.sh /e..." 9 seconds ago Up 9 seconds 0.0.0.0:5000->5000/tcp nifty_shaw
3、另一节点可以访问
[root@xserver1 ~]# curl http://192.168.200.70:5000/v2/_catalog
{"repositories":[]}
4、标记一下tag,必须要带有私有仓库的ip:port
[root@localhost ~]# docker tag liu 192.168.200.70:5000/centos
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 2d4f4b5309b1 4 months ago 26.2 MB
192.168.200.70:5000/centos latest 2d4f4b5309b1 4 months ago 26.2 MB
liu latest 2d4f4b5309b1 4 months ago 26.2 MB
6、把标记的镜像给推送到私有仓库
配置文件
[root@localhost ~]# vi /etc/docker/daemon.json
{
"registry-mirrors":["https://dhq9bx4f.mirror.aliyuncs.com"],"insecure-registries":["192.168.200.70:5000"]
}
~
~
~
~
~
~
~
~
~
"/etc/docker/daemon.json" 3L, 110C written
[root@localhost ~]# systemctl restart docker
推送的时候要确保镜像连着的容器是开启的,如果没有开启可以用命令docker start (容器id)
[root@localhost ~]# docker run -itd -p 5000:5000 192.168.200.70:5000/centos
532f92bddd467470ab20a5ab69fa145793894fff7d266366f1bdde831d6e4560
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
532f92bddd46 192.168.200.70:5000/centos "/entrypoint.sh /e..." 19 seconds ago Up 19 seconds 0.0.0.0:5000->5000/tcp goofy_yonath
1eb165757b68 registry "/entrypoint.sh /e..." 53 minutes ago Exited (2) 31 minutes ago nifty_shaw
[root@localhost ~]# docker push 192.168.200.70:5000/centos
The push refers to a repository [192.168.200.70:5000/centos]
b3f465d7c4d1: Pushed
a5f27630cdd9: Pushed
239a096513b5: Pushed
f5b9430e0e42: Pushed
3e207b409db3: Pushed
latest: digest: sha256:74bbdad7597dd3344bf953674ada592a997a16740ade2785073751530ef534d5 size: 1363
可以在另一节查看到
[root@xserver1 ~]# curl http://192.168.200.70:5000/v2/_catalog
{"repositories":["centos"]}