Docke 仓库
在公有仓库上传、下载、搜索 images
1.先要到 www.docker.com 或 https://hub.docker.com/上注册账户
2.终端中登录你注册的账户
[root@zx~]# docker login
Username: 你创建的用户
Password: 你的密码
Login Succeeded
- 上传你自己的镜像到云上
[root@zx~]# docker ps
[root@zx ~]# docker commit 1ad15487827f wangjiadee/test
[root@zx~]# docker push wangjiadee/test
我注册的用户名为 wangjiadee 所以我的仓库名也就是 wangjiadee,后面的 test 是我的镜像名
等上传成功后,你就可以在 www.docker.com 中登录你的账户,可以看到你上传的镜像了
在别的电脑执行 docker pull wjli/test
就可以很方便的把你上传的镜像下载下来使用
代码解释:
- 先pull下一个镜像 busybox 因为比较小 适合做实验
- 然后在打一个标签
- 上传到公共仓库去
- 接着你可以在https://hub.docker.com 去查看
5.然后在本地删除原来的镜像
6.在下载新的你的仓库的镜像
[root@localhost ~]# docker pull busybox
[root@localhost ~]# docker tag busybox:latest wangjiadee/busybox:v1
[root@localhost ~]# docker push wangjiadee/busybox
The push refers to repository [docker.io/wangjiadee/busybox]
6c0ea40aef9d: Layer already exists
v1: digest: sha256:dd97a3fe6d721c5cf03abac0f50e2848dc583f7c4e41bf39102ceb42edfd1808 size: 527
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 99acf599b3d0 21 minutes ago 366MB
<none> <none> e556ef1934a3 21 minutes ago 408MB
centos httpd 5793f9249cc7 56 minutes ago 303MB
ralph/nginx latest 8eed31b6faa7 6 hours ago 126MB
richarvey/nginx-php-fpm latest bb49f1636b1a 7 days ago 444MB
nginx latest ab56bba91343 12 days ago 126MB
nginx latest ab56bba91343 12 days ago 126MB
php latest d1d1e483ba07 12 days ago 401MB
mysql 5.7 383867b75fd2 12 days ago 373MB
mysql latest b8fd9553f1f0 12 days ago 445MB
busybox latest 19485c79a9bb 2 weeks ago 1.22MB
wangjiadee/busybox v1 19485c79a9bb 2 weeks ago 1.22MB
centos 7 67fa590cfc1c 4 weeks ago 202MB
centos latest 67fa590cfc1c 4 weeks ago 202MB
centos latest 67fa590cfc1c 4 weeks ago 202MB
[root@localhost ~]# docker rmi wangjiadee/busybox:v1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 99acf599b3d0 22 minutes ago 366MB
<none> <none> e556ef1934a3 22 minutes ago 408MB
centos httpd 5793f9249cc7 57 minutes ago 303MB
ralph/nginx latest 8eed31b6faa7 6 hours ago 126MB
richarvey/nginx-php-fpm latest bb49f1636b1a 7 days ago 444MB
nginx latest ab56bba91343 12 days ago 126MB
nginx latest ab56bba91343 12 days ago 126MB
php latest d1d1e483ba07 12 days ago 401MB
mysql 5.7 383867b75fd2 12 days ago 373MB
mysql latest b8fd9553f1f0 12 days ago 445MB
busybox latest 19485c79a9bb 2 weeks ago 1.22MB
centos 7 67fa590cfc1c 4 weeks ago 202MB
centos latest 67fa590cfc1c 4 weeks ago 202MB
centos latest 67fa590cfc1c 4 weeks ago 202MB
[root@localhost ~]# docker pull wangjiadee/busybox:v1
v1: Pulling from wangjiadee/busybox
[DEPRECATION NOTICE] registry v2 schema1 support will be removed in an upcoming release. Please contact admins of the docker.io registry NOW to avoid future disruption.
7c9d20b9b6cd: Already exists
Digest: sha256:7266973cc4c237277b6dad0158e3d37485a99225b80506ed03eb56b5cdf16263
Status: Downloaded newer image for wangjiadee/busybox:v1
docker.io/wangjiadee/busybox:v1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 99acf599b3d0 22 minutes ago 366MB
<none> <none> e556ef1934a3 23 minutes ago 408MB
centos httpd 5793f9249cc7 58 minutes ago 303MB
ralph/nginx latest 8eed31b6faa7 6 hours ago 126MB
richarvey/nginx-php-fpm latest bb49f1636b1a 7 days ago 444MB
nginx latest ab56bba91343 12 days ago 126MB
nginx latest ab56bba91343 12 days ago 126MB
php latest d1d1e483ba07 12 days ago 401MB
mysql 5.7 383867b75fd2 12 days ago 373MB
mysql latest b8fd9553f1f0 12 days ago 445MB
wangjiadee/busybox v1 19485c79a9bb 2 weeks ago 1.22MB
busybox latest 19485c79a9bb 2 weeks ago 1.22MB
centos 7 67fa590cfc1c 4 weeks ago 202MB
centos latest 67fa590cfc1c 4 weeks ago 202MB
centos latest 67fa590cfc1c 4 weeks ago 202MB
在私有仓库上传、下载、搜索 images
- 在另一台机上创建私有仓库(192.168.28.202)
Docker Hub 作为 Docker 默认官方公共镜像;如果想自己搭建私有镜像仓库,官方也
提供 registry 镜像,使得搭建私有仓库非常简单。
下载 registry 镜像并启动
#docker pull registry
#docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always
–name registry registry
测试,查看镜像仓库中所有镜像
#curl http://192.168.28.202:5000/v2/_catalog
{“repositories”:[]} - 在 192.168.28.161 上配置使用私有仓库
1)配置私有仓库可信任
#vi /etc/docker/daemon.json
{
“registry-mirrors”: [ “https://registry.docker-cn.com”],
“insecure-registries”: [“192.168.28.202:5000”]
}
#systemctl restart docke2、打标签
#docker tag centos:httpd 192.168.28.202:5000/centos-httpd:v2
3、上传
#docker push 192.168.28.202:5000/centos-httpd:v2
4、下载
#docker pull 192.168.28.202:5000/centos-httpd:v2
5、列出镜像标签
#curl http://192.168.28.202:5000/v2/centos-httpd/tags/list