仓库(Repository)是集中存放镜像的地方。
一个容易混淆的概念是注册服务器(Registry)。实际上注册服务器是管理仓库的具体服务器,每个服务器上可以有多个仓库,而每个仓库下面有多个镜像。从这方面来说,仓库可以被认为是一个具体的项目或目录。例如对于仓库地址 docker.io/ubuntu 来说,docker.io 是注册服务器地址,ubuntu 是仓库名。
大部分时候,并不需要严格区分这两者的概念。
Docker Hub
Docker 官方维护了一个公共仓库 Docker Hub,可以在此免费注册账号,相关命令如下。
# 登录docker login# 登出docker logout# 查找官方仓库中的镜像,官方镜像会有OFFICIAL标识docker search <关键字># 拉取镜像docker pull <镜像名># 推送自己的镜像到Docker Hub,username要替换为自己的Docker账号用户名$ docker tag ubuntu:18.04 username/ubuntu:18.04$ docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEubuntu 18.04 275d79972a86 6 days ago 94.6MBusername/ubuntu 18.04 275d79972a86 6 days ago 94.6MB$ docker push username/ubuntu:18.04$ docker search usernameNAME DESCRIPTION STARS OFFICIAL AUTOMATEDusername/ubuntu
私有仓库 & 私有仓库高级配置
docker-registry是官方提供的工具,可以用于构建私有的镜像仓库。详见链接。
(因为大多数时候公司都会有自家的私有仓库,所以暂时跳过)
