5.1Docker Hub 公共镜像市场
1.登录
$ docker login # 登录
2.基本操作
搜寻镜像
$ docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 3540 [OK]
jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.3.1611 x8... 79 [OK]
tutum/centos Simple CentOS docker image with SSH access 33
......
pull镜像
$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
7b6bb4652a1b: Pull complete
Digest: sha256:c1010e2fe2b635822d99a096b1f4184becf5d1c98707cbccae00be663a9b9131
Status: Downloaded newer image for centos:latest
用户还可以在登录后通过 docker push命令将本地镜像推送到Docker Hub。
$ 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: xrichardyan
Password:
Login Succeeded
$ docker tag centos:latest xrichardyan/centos:1.0 # 先添加新的标签 username/centos:1.0 username必须是Docker Hub的username.
$ docker push xrichardyan/centos:1.0 # push成功
The push refers to a repository [docker.io/xrichardyan/centos]
99b28d9413e4: Mounted from library/centos
1.0: digest: sha256:c1010e2fe2b635822d99a096b1f4184becf5d1c98707cbccae00be663a9b9131 size: 529
3.自动创建
5.2时速云镜像市场
其中同步了所有Docker Hub的镜头,通过这个下载镜像会很快。
5.3搭建本地私有仓库
1.使用registry镜像创建私有仓库
$ docker run -d -p 5000:5000 registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry
90f4dba627d6: Pull complete
3a754cdc94a5: Pull complete
bf16d9b6d4c1: Pull complete
7eea83c9b7bb: Pull complete
23293c727551: Pull complete
Digest: sha256:295b693558f0bcc6dc389229b87bcce5d3385357086d444dd317435d8b2810c1
Status: Downloaded newer image for registry:latest
09701b529bf3e4240cdb03e23a6f7b740f0129bda243ec3dd38f61582fd44512
这将自动下载并启动一个registry容器,创建本地的私有仓库服务。
默认情况下,会将仓库创建在容器的/特么/registry目录下。也可以通过 -v 参数来讲镜像文件存放在本地指定的路径。
例如下面的例子讲上传的镜像放在/opt/data/registry 目录:
$ docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
a598c57237f40e70e25f03505e6b5c4d715fc5d20911284d970fd73f3f4fa223