Docker Hub当然是首选镜像仓,如果不想对所有人公开只想在局域网或公司内部使用,则有必要搭建私有仓来存储分发镜像。

搭建私有仓当然可以直接运行以下命令来创建个registry容器:

docker run -d -p : --restart=always --name registry registry:2

一条命令已经很简洁了,这里如果只是写这么一句话就实在太没必要了,所以本文介绍如何一步步编译出registry镜像。

registry官方路径:https://hub.docker.com/_/registry/

Docker registry镜像依赖关系是registry:latest -> alpine:3.4 -> scratch:latest

1 alpine镜像

Dockerfile路径:https://github.com/gliderlabs/docker-alpine/blob/8f23fc2e995ab8f7f0f5960c6a1ddd12f57efd0c/versions/library-3.4/Dockerfile

Docker Registry镜像依赖于alpine:3.4镜像,alpine镜像是一个基于Alpine Linux的一个Docker镜像,它拥有完整的包索引,它真的很小,编译出来只有4.803M。

2 scratch镜像
github 路径:https://github.com/fpco/haskell-scratch
alpine:3.4镜像依赖于scratch镜像,而scratch是一个包含了最少的共享库的Docker基础镜像,它不足5M。
关于scratch可以看这里的介绍https://www.fpcomplete.com/blog/2015/05/haskell-web-server-in-5mb
 
3 编译镜像
有了以上信息,就可以开始干活了:
3.1 从https://codeload.github.com/fpco/haskell-scratch/zip/master下载scratch,解压后进入haskell-scratch-master目录,执行make即可生成scratch镜像,如下:
# make
sha256:8cbba14eb7fe1eb44e53557028f622d3de6baf5b932e53b4522b7b525f3c42c3
sha256:659b6da402fd38431f58614b4c57fa6c6efec87702702446c8636628f434d246
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
haskell-scratch integer-simple 659b6da402fd seconds ago 3.811 MB
haskell-scratch integer-gmp 8cbba14eb7fe seconds ago 4.286 MB

执行成功后即可得到两个镜像,haskell-scratch:integer-simple和haskell-scratch:integer-gmp

为了使用方便,我们给scratch创建个tag,命令如下:

docker tag haskell-scratch:integer-gmp scratch

3.2 从https://codeload.github.com/gliderlabs/docker-alpine/zip/8f23fc2e995ab8f7f0f5960c6a1ddd12f57efd0c下载alpine,解压后进入docker-alpine-8f23fc2e995ab8f7f0f5960c6a1ddd12f57efd0c/versions/library-3.4目录执行build命令编译alpine镜像,命令如下:

docker build -t alpine:3.4 .

3.3 从https://codeload.github.com/docker/distribution-library-image/zip/3b4a84c1f152b60688e99d2efadf305479541482下载registry,解压后进入distribution-library-image-3b4a84c1f152b60688e99d2efadf305479541482目录,执行build命令编译registry镜像,命令如下:

docker build -t registry .

至此就有了自己一步步编译出来的registry镜像,那么创建个容器试试,命令如下:

# docker run -d -p : --restart=always --name registry registry
055d53fe984679128e2ab8404a4eb4087eb0eb1713368b048d030e8d65a8f56d
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
055d53fe9846 registry "/entrypoint.sh /etc/" minutes ago Up minutes 0.0.0.0:->/tcp registry

3.4 push镜像至私有仓

首先,想要push镜像至私有仓,镜像名必须满足一定格式,格式为registry_host:port/image_name:tag

我们给hello-world:latest镜像创建个tag,命令如下:

# docker tag hello-world localhost:5000/hello-world
# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
hello-world                  latest              c54a2cc56cbb        12 weeks ago        1.848 kB
localhost:5000/hello-world   latest              c54a2cc56cbb        12 weeks ago        1.848 kB

然后docker push就可以将这个镜像提交到私有仓中了,如下:

docker push localhost:/hello-world
The push refers to a repository [localhost:/hello-world]
a02596fdd012: Pushed
latest: digest: sha256:a18ed77532f6d6781500db650194e0f9396ba5f05f8b50d4046b294ae5f83aa4 size:

接下来为了验证我们的私有仓可用,我将本地的hello-world镜像删除后来做验证,过程如下:

root@ *** :~# docker rmi localhost:/hello-world hello-world
Untagged: localhost:/hello-world:latest
Untagged: localhost:/hello-world@sha256:a18ed77532f6d6781500db650194e0f9396ba5f05f8b50d4046b294ae5f83aa4
Untagged: hello-world:latest
Untagged: hello-world@sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
Deleted: sha256:c54a2cc56cbb2f04003c1cd4507e118af7c0d340fe7e2720f70976c4b75237dc
Deleted: sha256:a02596fdd012f22b03af6ad7d11fa590c57507558357b079c3e8cebceb4262d7
root@ *** :~# docker run localhost:/hello-world
Unable to find image 'localhost:5000/hello-world:latest' locally
latest: Pulling from hello-world c04b14da8d14: Pull complete
Digest: sha256:a18ed77532f6d6781500db650194e0f9396ba5f05f8b50d4046b294ae5f83aa4
Status: Downloaded newer image for localhost:/hello-world:latest Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal. To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker Hub account:
https://hub.docker.com For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

至此,私有仓搭建成功。

Docker笔记——搭建私有仓的更多相关文章

  1. Docker Registry搭建私有仓库

    利用Registry镜像搭建Docker私有仓库遇到了很多坑,说来也是找到的资料都是杂而不精的东西,所以也没少走了弯路,现在回过头看去感觉好多坑还是别人给挖的··· 不过努力的最终结果还是好的,因为找 ...

  2. docker进阶-搭建私有企业级镜像仓库Harbor

    为什么要搭建私有镜像仓库   对于一个刚刚接触Docker的人来说,官方的Docker hub是用于管理公共镜像.既然官方提供了镜像仓库我们为什么还要去自己搭建私有仓库呢?虽然也可以托管私有镜像.我们 ...

  3. docker之搭建私有镜像仓库和公有仓库

    一.搭建私有仓库 1.docker pull registry #下载registry镜像并启动 2. docker run -d -v /opt/registry:/var/lib/registry ...

  4. Docker:搭建私有镜像仓储(image registry)(4)

    搭建私有仓储,其实本质上也是运行了一个官方提供的(Registry)镜像的容器:生产环境中,我们要搭建自己的专有仓储 下载registry镜像 docker pull registry 运行镜像 do ...

  5. Docker——Registry搭建私有镜像仓库

    前言 在 Docker 中,当我们执行 docker pull xxx 的时候,它实际上是从 registry.hub.docker.com 这个地址去查找,这就是Docker公司为我们提供的公共仓库 ...

  6. Ubuntu Docker Registry 搭建私有仓库

    服务器版本 Ubuntu 16.04 LTS. 安装命令: $ docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --rest ...

  7. docker之搭建私有仓库

    一.私有仓库 1.防止网络原因:下载慢,访问不到的情况,需要在内网搭建一个私有仓库. 二.仓库镜像下载 [root@node03 ~]# docker pull registry 三.创建私有仓库容器 ...

  8. Docker:搭建私有仓库(Registry 2.4)

    一.背景 首先,Docker Hub是一个很好的用于管理公共镜像的地方,我们可以在上面找到想要的镜像(Docker Hub的下载量已经达到数亿次):而且我们也可以把自己的镜像推送上去.但是,有的时候, ...

  9. docker registry-v2 搭建私有仓库

    参考官方文档:https://docs.docker.com/registry/deploying/ 参考 :http://www.tuicool.com/articles/6jEJZj 本例子使用两 ...

随机推荐

  1. 自适应reset.js布局 用于手机端页面编写

    以下是reset.js具体内容,是从淘宝网站拔下来的.把它存为js文件引入html里,它的默认尺寸是iphone4的分辨率也就是320*480,美工给你的图不管多少尺寸用ps量图后像素值(px)除以4 ...

  2. SQL SEVER 时间格式转换

    常用:时分秒(HH:mm:ss):Select CONVERT(varchar(100), GETDATE(), 8) : 10:57:46年月日 (yyyyMMdd):Select CONVERT( ...

  3. 项目工程中的WebRoot与WebContent有什么区别?

    [1] 在MyEclipse中创建web项目后,web程序的根目录文件夹是WebRoot,而创建dynam web project时候,web程序的根 目录文件夹是WebContent,他们之间没有本 ...

  4. 安装Oracle数据库心得

    学到Oracle数据库了,想在自己电脑上安装个Oracle数据库.在网上下载了一个Oracle18c版 下边是我安装Oracle18c版的数据库失败,后来在卸载过程中遇到的问题: 1.用Univers ...

  5. [工作积累] TAA Ghosting 的相关问题

    因为TAA要使用上一帧的历史结果,那么在相机移动的时候,颜色就会有残留,出现ghosting(残影). 由于上一帧历史是累积的,是由上一帧的直接渲染结果和上上帧的结果做了合并,所以ghosting并不 ...

  6. 【缓存算法】FIFO,LFU,LRU

    一.FIFO算法 FIFO(First in First out),先进先出.其实在操作系统的设计理念中很多地方都利用到了先进先出的思想,比如作业调度(先来先服务),为什么这个原则在很多地方都会用到呢 ...

  7. 使用dotenv 管理nodejs 应用的环境变量&&docker-compose 运行

      说明dotenv 是一个很方便的符合12 factor 的环境变量管理工具,使用很方便,实际上里面的代码也不是很多 测试使用docker 进行环境部署,为了方便分发使用pkg 进行打包,使用alp ...

  8. Just nothing

    I know that's I should do what I can to find a job But I can't focus on it I am always sad and I can ...

  9. chrome添加离线插件

    1.首先用户点击谷歌浏览器右上角的自定义及控制按钮,在下拉框中选择工具选项,然后点击扩展程序来启动Chrome浏览器的扩展管理器页面. 2.在打开的谷歌浏览器的扩展管理器中用户可以看到一些已经安装程序 ...

  10. attr跟prop的区别:

    prop()函数的结果: 1.如果有相应的属性,返回指定属性值. 2.如果没有相应的属性,返回值是空字符串. attr()函数的结果: 1.如果有相应的属性,返回指定属性值. 2.如果没有相应的属性, ...