docker学习(8) 在mac机上搭建私有仓库

简介: docker的私有仓库类似maven的私服,一般用于公司内部搭建一个类似docker hub的环境,这样上传、下载镜像速度较快,本文将演示如何在mac上利用docker-machine搭建无需SSL证书的私有仓库。

docker的私有仓库类似maven的私服,一般用于公司内部搭建一个类似docker hub的环境,这样上传、下载镜像速度较快,本文将演示如何在mac上利用docker-machine搭建无需SSL证书的私有仓库。

一、查看docker-machine虚拟机IP

docker-machine ip default

默认情况下docker-toolbox创建的虚拟机名称为default,如果您的虚拟机名字不是这个,上面命令最后的default换成真实的虚拟机名字,假设default分配的IP为192.168.99.100

 

二、修改虚拟机中的docker启动配置

由于docker最新版本默认访问私服时,强制采用SSL安全连接,但一般内部应用时不需要这么高的安全级别,参考下面的做法降低安全设置:

docker-machine ssh default
sudo vi /var/lib/boot2docker/profile

在profile文件最后加上:

EXTRA_ARGS="--insecure-registry 192.168.99.100:5000"

然后exit退出default,输入以下命令重启虚拟机

docker-machine restart default

 

三、创建私服容器

dao pull registry 

docker run -d -p 5000:5000 --restart=always -h registry \
 --name registry \
 -v /Users/yjmyzz/data/registry:/tmp/registry \
 registry

第1行的dao pull registry表示将从daocloud.io上拉取registry镜像,如果本机已经有该镜像,可以省略。

-v 后面的路径,大家改成实际路径,这个目录用于存放push到私有仓库的images文件。

 

四、测试上传、下载

4.1 先从daocloud.io上拉一个hello-world

hello-world这个镜像只有960b,可以拿这个练手

dao pull hello-world

 4.2 将hello-world打标签成私服镜像

docker tag hello-world 192.168.99.100:5000/hello-world

上面的ip要换真实的虚拟机ip,执行完以后,本机镜像文件应该能看到这个images,见下图:

注:原始镜像hello-world与打tag后的镜像具有相同的IMAGE ID,说明这二个镜像就是同一个,只是tag不同而已。

4.3 上传到私有仓库

docker push 192.168.99.100:5000/hello-world

顺利的话,应该很快就能上传完:

  ~  docker push 192.168.99.100:5000/hello-world
The push refers to a repository [192.168.99.100:5000/hello-world] (len: 1)
Sending image list
Pushing repository 192.168.99.100:5000/hello-world (1 tags)
3f12c794407e: Image successfully pushed
975b84d108f1: Image successfully pushed
Pushing tag for rev [975b84d108f1] on {http://192.168.99.100:5000/v1/repositories/hello-world/tags/latest}

可以直接在浏览器里访问:http://192.168.99.100:5000/v1/search,如果能看到

{
    "num_results": ​1,
    "query": "",
    "results": 
[
        {
            "description": "",
            "name": "library/hello-world"
        }
    ]
}

说明上传成功

4.4 从私有仓库下载

因为本机已经有hello-world的镜像了,为了方便验证,先把它删除:

docker rmi -f hello-world 192.168.99.100:5000/hello-world
#或
#docker rmi -f 975b84d108f1 #即:hello-world的IMAGE ID

然后下载:

docker pull 192.168.99.100:5000/hello-world

内网环境,应该很快就能下载完成:

  ~  docker pull 192.168.99.100:5000/hello-world
Using default tag: latest
Pulling repository 192.168.99.100:5000/hello-world
975b84d108f1: Download complete
3f12c794407e: Download complete
Status: Downloaded newer image for 192.168.99.100:5000/hello-world:latest
192.168.99.100:5000/hello-world: this image was pulled from a legacy registry.  
Important: This registry version will not be supported in future versions of docker.

注:如果私有仓库要放置在公网上,建议还是按官方推荐的做法,设置SSL证书,强制走https协议,否则将有安全风险。

 

参考文章:
1. Docker私有Registry在CentOS6.X下安装指南 
2. 搭建私有 Docker 仓库服务器
3. Use private docker registry in OS-X
4. Deploying a registry server
5. allow insecure registry in host provisioned with docker-machine
6. Adding trusted root certificates to the server  
7. How To Set Up a Private Docker Registry on Ubuntu 14.04

目录
相关文章
|
24天前
|
存储 Docker 容器
入职必会-开发环境搭建50-Docker必会搭建Docker私有仓库
Docker官方的Docker hub(https://hub.docker.com)是一个用于管理公共镜像的仓库,我们可以从上面拉取镜像到本地也可以把我们自己的镜像推送上去。但是有时候我们的服务器无法访问互联网或者不希望将自己的镜像放到公网当中,那么我们就需要搭建自己的Docker私有仓库来存储和管理自己的Docker镜像。
入职必会-开发环境搭建50-Docker必会搭建Docker私有仓库
|
22天前
|
Ubuntu Java Docker
docker 搭建私有仓库并发布私有镜像
docker 搭建私有仓库并发布私有镜像
191 1
|
6天前
|
jenkins 网络安全 持续交付
Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
7 0
|
8天前
|
Java 数据安全/隐私保护 Docker
SpringBoot Docker 发布到 阿里仓库
SpringBoot Docker 发布到 阿里仓库
22 0
|
2月前
|
存储 测试技术 Linux
Docker技术仓库
本文详细介绍了Docker中数据卷的作用、特点、管理方式,包括bindmounts和volumes挂载、Dockerfile中的数据卷使用、Docker仓库(公有与私有)以及DockerCompose在多容器应用中的应用。
|
2月前
|
数据安全/隐私保护 开发者 Docker
国内docker公开镜像站的关闭!别急,docker_image_pusher 使用Github Action将国外的Docker镜像转存到阿里云私有仓库
通过使用 docker_image_pusher 这样的开源项目,我们能够轻松地解决国内访问 Docker 镜像拉取速度慢及拉去失败的问题,同时保证了镜像的稳定性和安全性。利用 Github Action 的自动化功能,使得这一过程更加简单和高效。
1169 2
|
1月前
|
前端开发 Docker 容器
前端 CSS 经典:mac docker 效果
前端 CSS 经典:mac docker 效果
21 0
|
2月前
|
弹性计算 Ubuntu Linux
为什么要学习去使用云服务器,外网 IP能干什么,MAC使用Termius连接阿里云服务器。保姆级教学
为什么要学习去使用云服务器,外网 IP能干什么,MAC使用Termius连接阿里云服务器。保姆级教学
|
2月前
|
应用服务中间件 Shell nginx
mac m1笔记本docker 安装nginx
mac m1笔记本docker 安装nginx
204 4
|
2月前
|
存储 持续交付 数据安全/隐私保护
实现镜像管理轻松搞定:Docker 仓库管理详解
实现镜像管理轻松搞定:Docker 仓库管理详解
403 1