centos7搭建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

注意:若是發生修改,想要讓修改生效,請重啓python

install docker

若是安裝的請跳過linux

>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-worlddocker

    • 打標籤 > docker tag docker.io/hello-world localhost:5000/hello-world 必須得這樣寫localhost:5000 or 127.0.0.1:5000/hello-worldcentos

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

    • 重啓docker > service docker restartpython2.7

    • push images to 私有倉庫 > docker push localhost:5000curl

    • 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
相關文章
相關標籤/搜索