[TOC] ## 概述 有时候使用 Docker Hub 这样的公共仓库可能不方便,用户可以创建一个本地仓库供私人使用。 `docker-registry` 是官方提供的工具,可以用于构建私有的镜像仓库 ## 安装 `docker-registry` ### docker 安装 `sudo docker run -d -p 5000:5000 -v /home/user/registry-conf:/registry-conf -e DOCKER_REGISTRY_CONFIG=/registry-conf/config.yml registry` > 仓库会被创建在容器的 /tmp/registry 下 ### 命令行安装 #### Ubuntu ``` sudo apt-get install -y build-essential python-dev libevent-dev python-pip liblzma-dev sudo pip install docker-registry ``` #### CentOS ``` sudo yum install -y python-devel libevent-devel python-pip gcc xz-devel sudo python-pip install docker-registry ``` #### 源码进行安装 ## 上传 tag 格式 `docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]` 查看 `docker images`,选择一个镜像,设置容器名字必须为设置的想上传的服务器 ip ``` docker tag nginx_idpcj:v1 192.168.1.3:5000/demo sudo docker push 192.168.1.3:5000/demo ... > Pushing tag for rev [ba5877dc9bec] on {http://192.168.7.26:5000/v1/repositories/test/tags/latest} ``` ### 用 curl 查看仓库中的镜像 ``` $ curl http://192.168.7.26:5000/v1/search {"num_results": 7, "query": "", "results": [{"description": "", "name": "library/miaxis_j2ee"}, {"description": "", "name": "library/tomcat"}, {"description": "", "name": "library/ubuntu"}, {"description": "", "name": "library/ubuntu_office"}, {"description": "", "name": "library/desktop_ubu"}, {"description": "", "name": "dockerfile/ubuntu"}, {"description": "", "name": "library/test"}]} ``` ### 仓库配置文件 config_sample.yml 配置 * `common`:基础配置 * `local`:存储数据到本地文件系统 * `s3`:存储数据到 AWS S3 中 * `dev`:使用`local`模板的基本配置 * `test`:单元测试使用 * `prod`:生产环境配置(基本上跟s3配置类似) 默认情况下使用的模板是 dev, 设置 `export SETTINGS_FLAVOR=dev` ``` common: loglevel: info search_backend: "_env:SEARCH_BACKEND:" sqlalchemy_index_database: "_env:SQLALCHEMY_INDEX_DATABASE:sqlite:////tmp/docker-registry.db" prod: loglevel: warn storage: s3 storage_path: /srv/docker smtp_host: localhost dev: loglevel: debug storage: local storage_path: /home/myself/docker test: storage: local storage_path: /tmp/tmpdockertmp ``` ## 报错 ### http: server gave HTTP response to HTTPS client ``` 在”/etc/docker/“目录下,创建”daemon.json“文件。在文件中写入: { "registry-mirrors": [ "https://hhrdjck4.mirror.aliyuncs.com", "http://192.168.0.164:5000" ], "insecure-registries": [ "192.168.0.164:5000, "192.168.0.165:5000", //多个私服写法,逗号分隔即可 ] } ``` 重启 docker 在 mac 中 `Preferences -> Daemon -> Basic` 添加`局域网 ip: 端口:` 如 `192.168.1.3:5000`