5.1 Docker Hub 公共镜像市场
docker 官方公共镜像仓库 https://hub.docker.com
国内的有时速云 https://hub.tenxcloud.com (跟docker官方镜像同步)
5.2 搭建本地私有仓库
5.2.1 使用registry镜像创建私有仓库
安装Docker后,可以通过官方的registry镜像来简单搭建一套本地私有仓库环境:
首先查看下registry的默认volume的目录
[[email protected] ~]# docker inspect registry
[[email protected] ~]# docker run -d -p 192.168.161.128:5000:5000 -v /data/registry:/var/lib/registry registry:latest
#/data/registry 为本地镜像文件存储目录
#/var/lib/registry为容器内仓库默认存放镜像的目录
2c00af3018e5cc1e57332da1987050293fe6d58905289350125a7f145468a464
[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c00af3018e5 registry "/entrypoint.sh /e..." 4 seconds ago Up 2 seconds 0.0.0.0:5000->5000/tcp elated_minsky
通过-v参数来将镜像文件存放在本地的指定路径。
5.2.2 管理私有仓库
使用docker tag 命令将这个镜像标记为 192.168.161.128:5000/ubuntu:14.04(格式为:docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]:
[[email protected] ~]# docker tag ubuntu:14.04 192.168.161.128:5000/ubuntu:14.04
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.161.128:5000/ubuntu 14.04 578c3e61a98c 2 weeks ago 223 MB
ubuntu 14.04 578c3e61a98c 2 weeks ago 223 MB
使用docker push 上传标记的镜像
[[email protected] ~]# docker push 192.168.161.128:5000/ubuntu
The push refers to a repository [192.168.161.128:5000/ubuntu]
70d93396f87f: Pushed
6ec525dfd060: Pushed
705419d10b13: Pushed
a4aaef726d02: Pushed
04964fddc946: Pushed
14.04: digest: sha256:e4cb2e8d951d1418075b261f76476b4ac33a0a2fcffb0a68e376dc81bb5a2611 size: 1359
验证:
[[email protected] ~]# ls /data/registry/
docker
在Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报错误。为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问。修改docker启动配置文件:
[[email protected] ~]# docker push 192.168.161.128:5000/ubuntu
The push refers to a repository [192.168.161.128:5000/ubuntu]
Get https://192.168.161.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client
[[email protected] ~]# vi /usr/lib/systemd/system/docker.service
找到ExecStart
添加
--insecure-registry 192.168.161.128:5000 \
重启服务器。即可解决
原文地址:https://www.cnblogs.com/lingxiaolong/p/9204298.html