linux下 部署镜像服务站,配置 Docker 镜像下载的本地 mirror 服务

Docker registry 工具现在已经很好的支持了 mirror 功能,使用它可以配置一个本地的 mirror 服务,将 pull 过的镜像 cache 在本地,这样其它主机再次 pull 的时候会极大提高响应速度。

使用 docker-compose 启动 registry mirror 服务

以 Ubuntu 为例,首先要安装 docker 和 docker-compose。

安装 docker

$sudo wget -qO- https://get.docker.com/ | sh

安装 docker-compose

$sudo pip install docker-compose

之后,在本地创建 /opt/data/registry 目录,作为镜像文件的存储位置;创建 /opt/data/Redis 目录,作为 redis 数据的存放位置。

编写一个 docker-compose.yml 文件。

该文件将启动一个 registry 容器监听在本地的 5000 端口,并使用一个 redis 容器作为小文件的 cache。

内容如下:

# This compose file will start 2 containers: registry and redis.

# registry container will listen on host port 5000,

# and depend on the redis container as the cache scheme.

registry:

image: registry:latest

cpu_shares: 10

environment:

- STANDALONE=false

- MIRROR_SOURCE=https://registry-1.docker.io

- MIRROR_SOURCE_INDEX=https://index.docker.io

- CACHE_REDIS_HOST=redis

- CACHE_REDIS_PORT=6379

- DEBUG=false

hostname: docker-registry

links:

- redis:redis

mem_limit: 512m

ports:

- "5000:5000"

privileged: false

restart: always

user: root

volumes:

- /opt/data/registry:/tmp/registry

redis:

image: redis:3.0

cpu_shares: 10

expose:

- "6379"

mem_limit: 512m

restart: always

volumes:

- /opt/data/redis:/data

之后,启动服务。

$docker-compose up -d

配置主机使用 mirror 服务

在其它主机上,配置 docker 的配置文件(例如 /etc/default/docker),添加一行:

DOCKER_OPTS="$DOCKER_OPTS --registry-mirror http://localmirror:5000"

其中 localmirror 替换为刚才配置了 mirror 服务的机器地址。

之后重启 docker 服务。

$sudo service docker restart

测试

随便下载一个镜像,比如 ubuntu:14.04,正常需要十几分钟。

删除下载的镜像,再次下载,一分钟不到,就下载完毕了。

Docker 的详细介绍:请点这里

Docker 的下载地址:请点这里

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值