synchronization
This commit is contained in:
6
Docker/Dockerfile/Cache-Registry/Dockerfile
Normal file
6
Docker/Dockerfile/Cache-Registry/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM registry:latest
|
||||
|
||||
ENV PROXY_REMOTE_URL="" \
|
||||
DELETE_ENABLED="true"
|
||||
|
||||
COPY ./entrypoint.sh /entrypoint.sh
|
56
Docker/Dockerfile/Cache-Registry/README.md
Normal file
56
Docker/Dockerfile/Cache-Registry/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
> 本文作者:丁辉
|
||||
|
||||
# 镜像仓库代理服务
|
||||
|
||||
## 优点
|
||||
|
||||
1. **加速后续拉取**:同一个镜像只需从 Docker Hub 拉取一次,后续所有团队的拉取请求都会从本地缓存服务器获取,速度极快。
|
||||
2. **节省带宽**:减少对公网 Docker Hub 的重复请求,尤其适合带宽有限或按流量计费的环境。
|
||||
|
||||
## 镜像仓库地址
|
||||
|
||||
| 站点名 | URL | 备注 |
|
||||
| :---------: | :--------------------------: | :--------------------------------------------------------: |
|
||||
| DockerHub | https://registry-1.docker.io | 拉取镜像需要带上 `library` (可能就我有这情况吧,没仔细深究) |
|
||||
| Quay | https://quay.io | |
|
||||
| Gcr | https://gcr.io | |
|
||||
| Ghcr | https://ghcr.io | |
|
||||
| K8sgcr | https://k8s.gcr.io | |
|
||||
| Registryk8s | https://registry.k8s.io | |
|
||||
|
||||
## 已构建好的镜像
|
||||
|
||||
```bash
|
||||
hub.offends.cn/registry-proxy:latest
|
||||
```
|
||||
|
||||
## 启动容器
|
||||
|
||||
[仓库地址](https://gitee.com/offends/Kubernetes/tree/main/Docker/Dockerfile/Cache-Registry)
|
||||
|
||||
- Docker
|
||||
|
||||
```bash
|
||||
docker run -itd \
|
||||
--restart always \
|
||||
-p 80:5000 \
|
||||
-v "/etc/localtime:/etc/localtime" \
|
||||
-v "/var/lib/registryproxy:/var/lib/registry" \
|
||||
-e PROXY_REMOTE_URL="https://registry-1.docker.io/library" \
|
||||
--name=registry-proxy \
|
||||
hub.offends.cn/registry-proxy:latest
|
||||
```
|
||||
|
||||
- Docker-compose
|
||||
|
||||
> 文件在本仓库当前目录下, 修改 `PROXY_REMOTE_URL` 参数后即可使用
|
||||
|
||||
```bash
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
- Kubernetes
|
||||
|
||||
**查看此篇文档**
|
||||
|
||||
[Kubernetes部署Registry镜像仓库缓存服务](https://gitee.com/offends/Kubernetes/tree/main/Docker/Dockerfile/Cache-Registry/README.md)
|
13
Docker/Dockerfile/Cache-Registry/docker-compose.yaml
Normal file
13
Docker/Dockerfile/Cache-Registry/docker-compose.yaml
Normal file
@@ -0,0 +1,13 @@
|
||||
version: "3"
|
||||
services:
|
||||
registryproxy:
|
||||
image: "hub.offends.cn/registry-proxy:latest"
|
||||
container_name: "registryproxy"
|
||||
restart: "always"
|
||||
volumes:
|
||||
- "/etc/localtime:/etc/localtime"
|
||||
- "/var/lib/registryproxy:/var/lib/registry"
|
||||
environment:
|
||||
- "PROXY_REMOTE_URL=http://registry:5000"
|
||||
ports:
|
||||
- "5000:5000"
|
37
Docker/Dockerfile/Cache-Registry/entrypoint.sh
Normal file
37
Docker/Dockerfile/Cache-Registry/entrypoint.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
|
||||
#############################################################################################
|
||||
# 用途: 定制缓存 Registry 镜像
|
||||
# 作者: 丁辉
|
||||
# 编写时间: 2024-06-29
|
||||
#############################################################################################
|
||||
|
||||
set -e
|
||||
|
||||
# 配置 Headers
|
||||
sed -i "/headers:/a\ Access-Control-Allow-Origin: ['*']" /etc/docker/registry/config.yml
|
||||
sed -i "/headers:/a\ Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']" /etc/docker/registry/config.yml
|
||||
sed -i "/headers:/a\ Access-Control-Expose-Headers: ['Docker-Content-Digest']" /etc/docker/registry/config.yml
|
||||
|
||||
# 检查环境变量PROXY_REMOTE_URL是否非空, 检查配置文件中变量出现的次数是否为0
|
||||
if [ -n "$PROXY_REMOTE_URL" ] && [ $(grep -c "$PROXY_REMOTE_URL" "/etc/docker/registry/config.yml") -eq 0 ]; then
|
||||
echo "proxy:" >> /etc/docker/registry/config.yml
|
||||
echo " remoteurl: $PROXY_REMOTE_URL" >> /etc/docker/registry/config.yml
|
||||
# 可以提供用户名和密码保持私密
|
||||
# echo " username: $PROXY_USERNAME" >> /etc/docker/registry/config.yml
|
||||
# echo " password: $PROXY_PASSWORD" >> /etc/docker/registry/config.yml
|
||||
echo "----- Enabled Proxy To Remote -----"
|
||||
fi
|
||||
# 判断是否开启 Registry 镜像镜像清理
|
||||
if [ "$DELETE_ENABLED" = "true" ] && [ $(grep -c "delete:" /etc/docker/registry/config.yml) -eq 0 ]; then
|
||||
sed -i '/rootdirectory:/a\ delete:' /etc/docker/registry/config.yml
|
||||
sed -i '/delete:/a\ enabled: true' /etc/docker/registry/config.yml
|
||||
echo "----- Enabled Local Storage Delete -----"
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
*.yaml|*.yml) set -- registry serve "$@" ;;
|
||||
serve|garbage-collect|help|-*) set -- registry "$@" ;;
|
||||
esac
|
||||
|
||||
exec "$@"
|
Reference in New Issue
Block a user