centos7搭建docker私有仓库

本文介绍如何在 CentOS 7 上部署 Docker 的私有仓库,包括关闭防火墙和 SELinux,安装 Docker,搭建私有仓库并解决常见错误,最后测试私有仓库的功能。

centos7-docker私有仓库

关闭防火墙

>systemctl stop firewalld.service  # 本次关闭
>systemctl disable firewalld.service # 开机不启动

关闭本地selinux防火墙

用 getenforce 命令来验证 selinux防火墙 的状态(Enforcing:强制,permissive:宽容模式,disabled:关闭)
> getenforce
Enforcing
> vi /etc/sysconfig/selinux 
修改 SELINUX=disabled

注意:如果发生修改,想要让修改生效,请重启

install docker

如果安装的请跳过

>yum install docker
>service docker start
>chkconfig docker on

本地私有仓库registry

  • 下载 >docker pull registry
  • 搭建仓库 > docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
    • BUG
      • wordkey: registry._setup_database.lock
    Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 507, in spawn_worker worker.init_process() File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/ggevent.py", line 193, in init_process super(GeventWorker, self).init_process() File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 114, in init_process self.wsgi = self.app.wsgi() File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 66, in wsgi self.callable = self.load() File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load return self.load_wsgiapp() File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 356, in import_app import(module) File "/usr/local/lib/python2.7/dist-packages/docker_registry/wsgi.py", line 27, in <module> from .search import * # noqa File "/usr/local/lib/python2.7/dist-packages/docker_registry/search.py", line 14, in <module> INDEX = index.load(cfg.search_backend.lower()) File "/usr/local/lib/python2.7/dist-packages/docker_registry/lib/index/init.py", line 82, in load return db.SQLAlchemyIndex() File "/usr/local/lib/python2.7/dist-packages/docker_registry/lib/index/db.py", line 86, in init self._setup_database() File "/usr/local/lib/python2.7/dist-packages/docker_registry/toolkit.py", line 330, in wrapper os.remove(lock_path) OSError: [Errno 2] No such file or directory: './registry._setup_database.lock' ``` 添加参数: -e GUNICORN_OPTS=["--preload"] docker run -d -p 5000:5000 -v /data/registry:/tmp/registry -e GUNICORN_OPTS=["--preload"] docker.io/registry
  • check 仓库 > curl 127.0.0.1:5000/v1/search {"num_results": 0, "query": "", "results": []}
  • 上传 本地库
    • 下载一个测试 镜像 > docker pull hello-world

    • 打标签 > docker tag docker.io/hello-world localhost:5000/hello-world 必须得这样写localhost:5000 or 127.0.0.1:5000/hello-world

    • 修改配置 > vi /etc/sysconfig/docker 添加如下内容: OPTIONS='--selinux-enabled --insecure-registry {registry_ip}:5000'

    • 重启docker > service docker restart

    • push images to 私有仓库 > docker push localhost:5000

    • check > curl 127.0.0.1:5000/v1/search {"num_results": 1, "query": "", "results": [{"description": "", "name": "library/hello-world"}]}

  • test (使用另外一台机)
    • 修改配置 > vi /etc/sysconfig/docker 添加如下内容: OPTIONS='--selinux-enabled --insecure-registry {registry_ip}:5000'
    • 重启
    • pull > docker pull 10.10.1.92:5000/hello-world

转载于:https://my.oschina.net/u/2362111/blog/711636

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值