docker镜像容器仓库的核心概念(跟我学docker-docker镜像仓库管理)
docker镜像容器仓库的核心概念(跟我学docker-docker镜像仓库管理)CREATEDIMAGE ID常用命令,查看本地仓库image: docker imagesREPOSITORYTAG
在学习docker仓库管理之前,先了解docker另外2个核心概念
docker核心概念- 镜像(Image)
- 容器(Container)
- 仓库(Repository)
解释如下:
镜像:类似虚拟机镜像
容器:类似linux系统环境,运行和隔离应用。容器从镜像启动的时候,docker会在镜像的最上一层创建一个可写层,镜像本身是只读的,保持不变。
仓库:每个仓库存放某一类镜像。
关系图如下所示:
简单来说就是:一个docker服务的运行分为三个步骤:第一就是服务器本地要有mysql服务的镜像(以mysql为例),然后在docker容器中运行,此时这个mysql服务才算启动完成。而管理mysql服务的镜像就是仓库。
常用命令,查看本地仓库image: docker images
REPOSITORY |
TAG |
IMAGE ID |
CREATED |
SIZE |
centos |
centos7 |
8652b9f0cb4c |
10 months ago |
204MB |
各个选项说明:
- REPOSITORY:表示镜像的仓库源
- TAG:镜像的标签
- IMAGE ID:镜像ID
- CREATED:镜像创建时间
- SIZE:镜像大小
我们可以从Docker Hub网站来搜索镜像,我们也可以使用 docker search 命令来搜索镜像。比如我们需要一个 httpd 的镜像来作为我们的 web 服务。我们可以通过 docker search 命令搜索 centos 来寻找适合我们的镜像。例如:docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 6744 [OK]
ansible/centos7-ansible Ansible on Centos7 134 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 130 [OK]
jdeathe/centos-ssh OpenSSH / Supervisor / EPEL/IUS/SCL Repos - … 120 [OK]
centos/systemd systemd enabled base container. 101 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 91
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 58 [OK]
tutum/centos Simple CentOS docker image with SSH access 48
centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 45
centos/httpd-24-centos7 Platform for running Apache httpd 2.4 or bui… 40
jdeathe/centos-ssh-apache-php Apache PHP - CentOS. 31 [OK]
kinogmt/centos-ssh CentOS with SSH 29 [OK]
guyton/centos6 From official centos6 container with full up… 10 [OK]
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-install… 8 [OK]
centos/tools Docker image that has systems administration… 7 [OK]
drecom/centos-ruby centos ruby 6 [OK]
mamohr/centos-java Oracle Java 8 Docker image based on Centos 7 3 [OK]
darksheer/centos Base Centos Image -- Updated hourly 3 [OK]
amd64/centos The official build of CentOS. 2
miko2u/centos6 CentOS6 日本語環境 2 [OK]
dokken/centos-7 CentOS 7 image for kitchen-dokken 2
mcnaughton/centos-base centos base image 1 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
smartentry/centos centos with smartentry 0 [OK]
starlabio/centos-native-build Our CentOS image for native builds 0 [OK]
各个选型说明如下:
- NAME: 镜像仓库源的名称
- DESCRIPTION: 镜像的描述
- OFFICIAL: 是否 docker 官方发布
- STARS: 类似 Github 里面的 star,表示点赞、喜欢的意思。
- AUTOMATED: 自动构建。
考虑到国内访问docker官网的现状,我们不得不使用阿里云的docker镜像仓库。
阿里云镜像获取地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
上传本地镜像到阿里云docker仓库:
$ docker login --username=yongo**** registry.cn-hangzhou.aliyuncs.com
$ docker push registry.cn-hangzhou.aliyuncs.com/lgy-feng/study-docker:[镜像版本号]
注:请根据实际镜像信息替换示例中的[ImageId]和[镜像版本号]参数。
测试阿里云本地仓库中:
$ docker pull registry.cn-hangzhou.aliyuncs.com/lgy-feng/study-docker:[镜像版本号]
扩展:如何本本地镜像重新命名上传到阿里云,使用tab标签自定义镜像版本号
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/lgy-feng/study-docker:[自定义镜像版本号]
至此docker的仓库使用说明已经结束!