$ 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: souyunku
Password: 输入密码
Login Succeeded 拉取镜像
你可以通过 docker search 命令来查找官方仓库中的镜像,并利用 docker pull 命令来将它下载到本地。
例如以 nginx 为关键词进行搜索:
$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 7636 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1214 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 490 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 279 [OK]
kong Open-source Microservice & API Management la… 143 [OK]
webdevops/php-nginx Nginx with PHP-FPM 93 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 88
可以看到返回了很多包含关键字的镜像,其中包括镜像名字、描述、收藏数(表示该镜像的受关注程度)、是否官方创建、是否自动创建。
官方的镜像说明是官方项目组创建和维护的,automated 资源允许用户验证镜像的来源和内容。
根据是否是官方提供,可将镜像资源分为两类。
一种是类似 centos 这样的镜像,被称为基础镜像或根镜像。这些基础镜像由 Docker 公司创建、验证、支持、提供。这样的镜像往往使用单个单词作为名字。
还有一种类型,比如 jwilder/nginx-proxy 镜像,它是由 Docker 的用户创建并维护的,往往带有用户名称前缀。可以通过前缀 username/ 来指定使用某个用户提供的镜像,比如 jwilder 用户。
另外,在查找的时候通过 --filter=stars=N 参数可以指定仅显示收藏数量为 N 以上的镜像。
下载官方 nginx 镜像到本地。
查看本地镜像
创建好私有仓库之后,就可以使用 docker tag 来标记一个镜像,然后推送它到仓库。例如私有仓库地址为 127.0.0.1:5000。
先在本机查看已有的镜像。
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 3f8a4339aadd 5 days ago 108MB 标记本地镜像
使用 docker tag 将 nginx:latest 这个镜像标记为 127.0.0.1:5000/nginx:latest。
格式为 docker tag IMAGE[:TAG] [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG]。
$ docker tag nginx:latest 127.0.0.1:5000/nginx:latest 上传标记镜像
使用 docker push 上传标记的镜像,到仓库
$ docker push 127.0.0.1:5000/nginx:latest
The push refers to repository [127.0.0.1:5000/nginx]
a103d141fc98: Pushed
73e2bd445514: Pushed
2ec5c0a4cb57: Pushed
latest: digest: sha256:926b086e1234b6ae9a11589c4cece66b267890d24d1da388c96dd8795b2ffcfb size: 948
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/nginx latest 3f8a4339aadd 5 days ago 108MB
用 curl 查看仓库中的镜像。