1、私仓搭建
docker pull registry#拉取镜像
docker images#查看镜像
mkdir -p /czx/myregistry 创建挂载目录
运行私有库registry (相当于本地有个是有docker hub)
docker run -d -p 5000:5000 -v /czx/myregistry/:/tmp/registry --restart=always --privileged=true registry
root@ubt:/# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
619be1103602: Pull complete
862815ae87dc: Pull complete
74e12953df95: Pull complete
6f0ce73649a0: Pull complete
ef4f267ce8ed: Pull complete
Digest: sha256:4fac7a8257b1d7a86599043fcc181dfbdf9c8f57e337db763ac94b0e67c6cfb5
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
root@ubt:/# mkdir -p /czx/myregistry
root@ubt:/# docker run -d -p 5000:5000 -v /czx/myregistry/:/tmp/registry --restart=always --privileged=true registry
68ffc60315f3b91020b30c0dfca353226fb669d047ec11640b98bddd18aae945
root@ubt:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
68ffc60315f3 registry "/entrypoint.sh /etc..." 3 seconds ago Up 1 second 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp admiring_varahamihira
curl -XGET http://自己的ip:5000/v2/_catalog
私仓搭建完成
2、打包并上传
这里把本地的nginx镜像打包,docker tag nginx 自己的ip:5000/nginx:1.0
查看镜像是否打包成功 docker images
尝试上传镜像至私有仓库 docker push 自己的ip:5000/nginx
报错Get "https://1.94.143.44:5000/v2/": http: server gave HTTP response to HTTPS client
需要修改daemon.json文件
root@ubt:/# vi /etc/docker/daemon.json
重启docker服务,systemctl restart docker
并启动registry,docker start [registry容器的id]
增加一行 "insecure-registries" : ["自己的ip:5000"]
再次上传,成功
3、下载镜像
这里在另外一台服务器下载此镜像
root@hcss-ecs-ed4e:/# docker pull 私有仓库ip:5000/nginx
注意这里也要配置daemon.json文件
可以参考Docker之将本地镜像推送到私有库_docker push 到私有仓库-CSDN博客
另外还可以配置仓库账号密码 参考 https://www.cnblogs.com/nulige/articles/10926088.html