美文网首页
Docker仓库的基本操作

Docker仓库的基本操作

作者: 苏康申 | 来源:发表于2019-05-28 11:10 被阅读0次

1.概念

仓库(Repository)是集中存放镜像的地方,分为公共仓库和私有仓库。一个容易与之混淆的概念是注册服务器(Registry)。实际上注册服务器是存放仓库的具体服务器,一个注册服务器上可以有多个仓库,而每个仓库下面可以有多个镜像。从这方面来说,可将仓库看做一个具体的项目或目录。例如对于仓库地址[private-docker.com/ubuntu](http://private-docker.com/ubuntu)来说,[private-docker.com](http://private-docker.com/)是注册服务器地址,ubuntu是仓库名。

2.登录仓库

Usage:  docker login [OPTIONS] [SERVER]

Log in to a Docker registry

Options:
  -p, --password string   Password
      --password-stdin    Take the password from stdin
  -u, --username string   Username

登录成功

localhost:yaf sukangshen$ 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: sukangshen
Password:
Login Succeeded

3.仓库中查找镜像

docker search centos
localhost:yaf sukangshen$ docker search centos
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
centos                             The official build of CentOS.                   5380                [OK]
ansible/centos7-ansible            Ansible on Centos7                              121                                     [OK]
jdeathe/centos-ssh                 CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86…   109                                     [OK]
consol/centos-xfce-vnc             Centos container with "headless" VNC session…   91                                      [OK]
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              56                                      [OK]

根据search结果,可将镜像资源分为两类。一种是类似centos这样的镜像,称为基础或根镜像。这些镜像是由docker公司创建、验证、支持、提供。这样的镜像往往使用单个单词作为名字。还有一种类型,比如ansible/centos7-ansible镜像,它是由docker用户ansible创建并维护的,带有用户名称前缀,表明是某用户下的某仓库。可以通过用户名称前缀user_name/镜像名来指定使用某个用户提供的镜像。另外,在查找的时候通过-s N参数可以指定仅显示评价为N星级以上的镜像。

4.搭建本地私有仓库

4.1使用registry镜像创建私有仓库
//1.在本地启动registry镜像,作为私有服务器,监听5000端口
localhost:yaf sukangshen$ docker run -d -p 5000:5000 registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:f87f2b82b4873e0651f928dcde9556008314543bd863b3f7e5e8d03b04e117f7
Status: Downloaded newer image for registry:latest
4d20b03dfc3a930caa986832887766cbf4bf5644e9cdeedbda4e384e60abaa52

这将自动下载并启动一个registry容器,创建本地的私有仓库服务。默认情况下,会将仓库创建在容器的/tmp/registry目录下。可以通过-v参数来将镜像文件存放在本地的指定路径。例如以下实例将上传的镜像放到/opt/data/registry目录:

//2.在本地启动registry镜像,作为私有服务器,监听5000端口,并指定本地目录数据卷
~/www/my_test/dnmp/www/registry,映射容器内/tmp/registry目录,目录不存在将会创建

localhost:yaf sukangshen$ docker run -d -p 5000:5000 -v 
~/www/my_test/dnmp/www/registry:/tmp/registry registry
2d524ae16c423bef1f00b7c67b04bea70587035b9f5bb40a9d1ca0534512072c
4.2管理私有仓库

4.2.1打标签

docker tag hello-world:v1 192.168.1.205:5000/test

REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
192.168.1.205:5000/test   latest              fce289e99eb9        4 months ago        1.84kB
hello-world               latest              fce289e99eb9        4 months ago        1.84kB
localhost:www sukangshen$ docker push 192.168.1.205:5000/test

4.2.2修改daemon.json,我直接在Docker客户端Daemon>Advanced修改后务必记得重启

{
  //表示信任这个私有仓库,不进行安全证书检查
 "insecure-registries":["192.168.206.128:5000"],
 "registry-mirrors": ["[https://4vehewku.mirror.aliyuncs.com](https://4vehewku.mirror.aliyuncs.com/)"]</pre>

}

4.2.3开始推送

docker push

localhost:www sukangshen$ docker push 192.168.1.205:5000/test
The push refers to repository [192.168.1.205:5000/test]
af0b15c8625b: Pushed
latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
localhost:www sukangshen$

4.2.4拉取

docker pull 

localhost:www sukangshen$ docker pull 192.168.1.205:5000/test
Using default tag: latest
latest: Pulling from test
Digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
Status: Image is up to date for 192.168.1.205:5000/test:latest

相关文章

  • docker 基本命令

    一,关于docker镜像操作的基本命令 二,关于docker容器操作的基本命令 三,关于docker仓库操作的基本命令

  • docker命令图谱

    基本命令 仓库相关操作 docker pull #从远程仓库拉取镜像到本地 docker push #推送...

  • Docker应用示例1--使用Docker创建Web服务

    1,目的 在已经掌握docker安装、docker仓库的基本使用、docker镜像和容器的基本操作和相互转化的基础...

  • Docker仓库的基本操作

    1.概念 仓库(Repository)是集中存放镜像的地方,分为公共仓库和私有仓库。一个容易与之混淆的概念是注册服...

  • Docker常用命令

    安装docker后,可以使用命令行: 基本命令 仓库相关操作 docker pull #从远程仓库拉取镜像...

  • Docker基础操作手册

    Docker操作总结 @Date 2018.08.24 基本操作 登录远程镜像仓库 镜像操作 根据指定路径的Doc...

  • Docker常用命令(零)

    docker的安装以及镜像,容器,仓库的基本操作 docker的安装(centos7中可以直接yum安装) yum...

  • docker草稿

    基本组成 Docker Image 镜像 Docker Container容器 Docker Registry仓库...

  • Docker常用操作命令

    镜像操作 安装镜像 镜像仓库 Docker仓库[https://hub.docker.com/]版本号在tags中...

  • docker-01-基操

    1.docker基本操作 2.docker镜像和仓库 最底端是引导文件系统-bootfs,容器启动后加到内存中,b...

网友评论

      本文标题:Docker仓库的基本操作

      本文链接:https://www.haomeiwen.com/subject/ushrtctx.html