- 1、注册账号
- https://hub.docker.com/ #在此页面注册账号,需要用户名,邮箱,密码(注:需要FQ才能注册,注册通过邮箱激活后可以通过网页登陆)
- 2、登陆docker hub
- root@localhost ~]# docker login
- #Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
- Username: *******
- Password:
- Login Succeeded
- 3、查找镜像 #可参考https://www.cnblogs.com/yangleitao/p/9683104.html
- [root@localhost ~]# docker search centos #可以加上版本号
- 4、下载镜像
- [root@localhost ~]# docker pull centos
- 5、上传镜像
- #我们可以把自己的镜像传到docker hub官网上,前提是已经注册了账号
- [root@localhost ~]# docker push image_name
- 1、使用registry镜像创建私有仓库
- [root@localhost ~]# docker search registry
- NAME DESCRIPTION STARS OFFICIAL AUTOMATED
- registry The Docker Registry 2.0 implementation for s… 2216 [OK]
- [root@localhost ~]# docker pull registry #直接下载镜像
- [root@localhost ~]# docker images #查看新下载的镜像
- 2、
- [root@localhost ~]# mkdir -p /data/registry/ #创建一个本地目录,等一下挂载
- [root@localhost ~]#
- [root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry/:/tmp/registry registry
- 599c0e1a298f5e7a19b9ba01ff314c3e3a26a22b3cba1e6800e21ffb54c8e9d5
- [root@localhost ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 599c0e1a298f registry "/entrypoint.sh /etc…" 9 seconds ago Up 7 seconds 0.0.0.0:5000->5000/tcp vibrant_engelbart
- 17c54a92a4e8 ubuntu:latest "/bin/bash" 6 days ago Up 6 days quizzical_bhabha
- [root@localhost ~]#
-d : 后台运行
-p : 宿主机跟容器映射端口 SERVER_PORT:CONTAINER_PORT
-v : 挂载宿主机目录到容器中作为数据卷, docker registry上传镜像默认存放到容器/var/lib/registry,将本地/data/registry目录挂载到容器中,避免删除容器是数据丢失
- 3、管理私有仓库
- [root@localhost ~]# docker run -d -p 5000:5000 registry
- 19003703c71307603cdb48fab242c96dc34c0e37f0dcfe2e568658abbea40557
- [root@localhost ~]# ps -aux|grep docker
- [root@localhost ~]# docker push 192.168.19.130:5000/test
- 报如下错:
- The push refers to a repository [192.168.19.130:5000/test]
- Get https://192.168.19.130:5000/v1/_ping: dial tcp 192.168.19.130:5000: getsockopt: connection refused
- 解决办法:
- a,执行
- echo '{ "insecure-registries":["192.168.19.130:5000"] }' >> /etc/docker/daemon.json #或者直接修改配置文件
- b, 重启docker client的docker 服务
- [root@localhost ~]# systemctl restart docker #如果容器没有开启也会报错
- [root@localhost ~]# docker push 192.168.19.130:5000/test1 #再次上传成功
- The push refers to repository [192.168.19.130:5000/test1]
- 8d7ea83e3c62: Pushed
- 6a061ee02432: Pushed
- f73b2816c52a: Pushed
- 6267b420796f: Pushed
- a30b835850bf: Pushed
- latest: digest: sha256:a819482773d99bbbb570626b6101fa37cd93a678581ee564e89feae903c95f20 size: 1357
- [root@localhost ~]# curl -XGET http://192.168.19.130:5000/v2/_catalog
- {"repositories":["test","test1"]}
- [root@localhost ~]# curl -XGET http://192.168.19.130:5000/v2/test1/tags/list
- {"name":"test1","tags":["latest"]}
- [root@localhost ~]#