Docker 私有仓库恢复实例详解
程序员文章站
2022-07-20 22:09:14
docker 私有仓库恢复
之前openstack平台由于停电等影响,导致之前制作的registry 私有仓库的主机挂掉,还好数据挂载在nfs中,然后现在尝试重新启动恢复...
docker 私有仓库恢复
之前openstack平台由于停电等影响,导致之前制作的registry 私有仓库的主机挂掉,还好数据挂载在nfs中,然后现在尝试重新启动恢复。
虚机安装nfs服务
apt-get install -y nfs-common
编辑 /etc/fstab
写入远程挂载地址
10.50.8.12:/export/dockerrepo /var/lib/docker/registry nfs defaults 0 0
然后进行挂载:
mount -a -v
输出如下结果,表明mount成功
root@docker-registry:/home/ubuntu# mount -a -v mount.nfs: timeout set for thu mar 26 13:12:44 2015 mount.nfs: trying text-based options 'vers=4,addr=10.50.8.12,clientaddr=10.0.0.244' nothing was mounted
可以用df来查看:
root@docker-registry:/home/ubuntu# df filesystem 1k-blocks used available use% mounted on /dev/vda1 165106028 1780156 156584392 2% / none 4 0 4 0% /sys/fs/cgroup udev 8211996 12 8211984 1% /dev tmpfs 1643392 348 1643044 1% /run none 5120 0 5120 0% /run/lock none 8216952 0 8216952 0% /run/shm none 102400 0 102400 0% /run/user 10.50.8.12:/export/dockerrepo 515931136 683008 489017344 1% /var/lib/docker/registry
创建新的registry
命令如下
# docker run -d -p 5000:5000 -v /var/lib/docker/registry:/tmp/registry registry
其中 -p是与主机进行端口映射,-v表示将主机的volume挂载到容器中,即将我们的nfs挂载到容器中,作为docker 私有仓库的存储使用。
查看是否创建成功
用curl命令来search其中的仓库文件是否存在:
root@docker-registry:/var/lib/docker/registry/images# curl http://127.0.0.1:5000/v1/search {"num_results": 8, "query": "", "results": [{"description": null, "name": "shipyard/rethinkdb"}, {"description": null, "name": "shipyard/shipyard"}, {"description": null, "name": "shipyard/shipyard-cli"}, {"description": null, "name": "library/mysql"}, {"description": null, "name": "library/ubuntu"}, {"description": null, "name": "library/registry"}, {"description": null, "name": "library/centos"}, {"description": null, "name": "tutum/influxdb"}]}
测试私有仓库
从私有仓库拉取ubuntu:14.04镜像。
root@docker-registry:/var/lib/docker/registry/images# docker pull 127.0.0.1:5000/ubuntu:14.04 pulling repository 127.0.0.1:5000/ubuntu 2103b00b3fdf: download complete 511136ea3c5a: download complete f0dde87450ec: download complete 76b658ecb564: download complete 4faa69f72743: download complete status: downloaded newer image for 127.0.0.1:5000/ubuntu:14.04
然后可以通过docker images来查看存在的images:
root@docker-registry:/var/lib/docker/registry/images# docker images repository tag image id created virtual size registry latest e33e81d7024c 5 days ago 413.7 mb 127.0.0.1:5000/ubuntu latest 2103b00b3fdf 2 weeks ago 192.7 mb 127.0.0.1:5000/ubuntu 14.04 2103b00b3fdf 2 weeks ago 192.7 mb
从私有仓库只需要10多秒即可将ubuntu的200多m的镜像给pull下来。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!