Docker私有仓库搭建记录

安装运行 docker-registry

1
2
3
4
docker run -d --name registry --restart=always \
-p 10.12.64.80:5000:5000 \
-v /data/docker/instance/registry/0/:/var/lib/registry \
registry

使用本地仓库(以mysql为例)

  1. 生成mysql的tag

    1
    docker tag mysql:5.7.23 registry:5000/mysql:5.7.23
  2. 将mysql推入私有仓库

    1
    docker push registry:5000/mysql:5.7.23

    如果出现如下提示,参考备注(2)
    The push refers to repository [registry:5000/mysql]
    Get https://registry:5000/v2/: http: server gave HTTP response to HTTPS client

  3. 从本地仓库获取镜像

    1
    2
    3
    4
    docker run --restart=always --name mysql-prod \
    -v /data/docker/instance/mysql/3/db:/var/lib/mysql \
    -v /data/docker/instance/mysql/3/conf:/etc/mysql/conf.d \
    -e MYSQL_ROOT_PASSWORD=123456 -d -p 10.12.64.60:3306:3306 registry:5000/mysql:5.7.23

备注

  1. registry:5000表示HOST:PORT格式

  2. 可以在**/etc/hosts**中配置registry对应的IP地址

  3. 编辑**/etc/docker/daemon.json**添加

    1
    {"insecure-registries":["registry:5000"]}
  4. 查看私有仓库镜像

    1
    curl -XGET registry:5000/v2/_catalog