-
拉取基础镜像
- 拉取 redis
docker pull redis
- 拉取 docker registry
docker pull registry
-
创建本地存储路径
-
redis 持久存储路径
mkdir /redisCache/
-
registry 持久存储路径
mkdir /dockerRegistry/registry
-
或添加云端存储
-
启动 redis
docker run --name dockerRedis -p 6379:6379 -v /redisCache:/data -d --restart=always redis:latest redis-server --appendonly yes --requirepass "XXXXXXXXXXX"
-
连接redis
docker run -it --rm --link dockerRedis:redis redis redis-cli -h dockerRedis -p 6379 -a "xxxxxxxxxxxxxx" # redis server密码:xxxxxxxxxxxxxx
-
配置 registry
service_conf/docker_registry_config.yaml
-
启动 registry
docker run -d -p 5000:5000 -v /dockerRegistry/registry:/var/lib/registry -e /dockerRegistry/config.yml --restart always --name MyRegistry registry # 本地存储路径: /dockerRegistry/registry # 本地配置: /dockerRegistry/config.yml
-
Copy an image from Docker Hub to our registry
-
Pull the ubuntu:16.04 image from Docker Hub.
docker pull ubuntu:18.04
-
Tag the image as localhost:5000/my-ubuntu. This creates an additional tag for the existing image. When the first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when pushing.
docker tag ubuntu:18.04 localhost:5000/my-ubuntu
-
Push the image to the local registry running at localhost:5000:
docker push 219.133.167.42:5000/my-ubuntu
-
Remove the locally-cached ubuntu:16.04 and localhost:5000/my-ubuntu images, so that you can test pulling the image from your registry. This does not remove the localhost:5000/my-ubuntu image from your registry.
docker image remove ubuntu:18.04 docker image remove localhost:5000/my-ubuntu
-
Pull the localhost:5000/my-ubuntu image from your local registry.
docker pull 219.133.167.42:5000/my-ubuntu
注意再远端服务器使用该镜像库时需要以下配置
vim /etc/docker/daemon.json # 添加镜像源 { "insecure-registries":["http://xxx.xxx.xxx.xxx:5000"] } # 重启 docker systemctl restart docker
-
-
Stop a local registry
docker container stop MyRegistry # or docker container stop MyRegistry && docker container rm -v MyRegistry
-
查看镜像库列表
curl -XGET http://219.133.167.42:5000/v2/_catalog
个人阿里镜像加速服务
"registry-mirrors":["https://xxxxxx.mirror.aliyuncs.com"]