搭建一个docker镜像仓库,缓存镜像请求
创建软件目录
mkdir -p registry
cd $_
docker构建脚本
services:
registry:
ports:
- 5000:5000
restart: always
container_name: registry-cache
volumes:
- ./data:/var/lib/registry
- ./config.yml:/etc/distribution/config.yml
image: registry
配置文件
version: 0.1
proxy:
remoteurl: https://registry-1.docker.io
ttl: 0
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
tag:
concurrencylimit: 8
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
启动
docker-compose up -d
docker-compose ps
1.小技巧,使用term
1.1 添加下行隧道
1.2 转发服务端docker套接字到本地
以下命令均在term端执行
ssh -L 5555:/var/run/docker.sock -N localhost
1.3 权限及账号准备
chmod 777 /var/run/docker.sock
useradd sync
usermod -s /bin/bash sync
echo "sync:sync" | chpasswd
apt install -y sudo
切换用户
cat > /etc/sudoers.d/sync << 'EOF'
sync ALL=(ALL) NOPASSWD: ALL
EOF
su - sync
1.4 同步镜像
export DOCKER_HOST=tcp://localhost:5555
# 本地到服务器
sudo docker save openjdk:11-jdk-slim | docker load
# 服务器到本地
docker save openjdk:11-jdk-slim | sudo docker load

文章版权声明:除非注明,否则均为边学边练网络文章,版权归原作者所有