文章目录
1.官方镜像仓库仓库
- 先在
https://hub.docker.com
注册帐号
docker login
登录docker hub 输入自己的用户名和密码
[root@server2 sysctl.d]# 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: wnccmyr
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
docker tag ubuntu:latest wnccmyr/ubuntu.latest
给自己本地的镜像打上标签
[root@server2 sysctl.d]# docker tag ubuntu:latest wnccmyr/ubuntu.latest
[root@server2 sysctl.d]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wnccmyr/ubuntu.latest latest d70eaf7277ea 4 weeks ago 72.9MB
ubuntu latest d70eaf7277ea 4 weeks ago 72.9MB
docker push wnccmyr/ubuntu:latest
把镜像上传
- 登录网页 ,发现已经成功上传
2. 搭建私有仓库
- dockerhub需要联网,慢,并且所有人都可以访问到,不够安全,企业内部的镜像放到外网不安全,docker公司把registry开源,可以搭建自己的私有仓库
docker pull registry:2
下载registry镜像docker run -d --name registry -p 5000:5000 -v /opt/registry:/var/lib/registry registry:2
我把把他挂载到指定目录/opt/registry
/var/lib/registry 目录自己可以查到,一般是默认目录
- 上传本地镜像到registry
##给我本地本就有的镜像ubuntu打上标签
[root@server1 registry]# docker tag ubuntu:latest localhost:5000/ubuntu:latest
[root@server1 registry]# docker push localhost:5000/ubuntu
-
可以看下刚才自己指定的目录下已经存在
-
为了测试,把本地的ubuntu镜像删除
docker rmi localhost:5000/ubuntu:latest
docker rmi ubuntu:latest
-
从本地进行下载
docker pull localhost:5000/ubuntu