Docker 私有仓库

2023-05-16

1. Registry

官方私有仓库,优点:简单;缺点:部署无法进行复杂的管理操作

1.1 镜像

docker pull registry:2.7.1
docker pull joxit/docker-registry-ui:latest   # 非必须,简单的界面

1.2 配置

mkdir -p /etc/docker/registry

cat > /etc/docker/registry/config.yml <<EOF
version: 0.1
log:
  accesslog:
    disabled: true
  level: debug
  formatter: text
  fields:
    service: registry
    environment: staging
storage:
  delete:
    enabled: true
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
    Access-Control-Allow-Origin: ['http://192.168.80.200']
    Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
    Access-Control-Allow-Headers: ['Authorization', 'Accept']
    Access-Control-Max-Age: [1728000]
    Access-Control-Allow-Credentials: [true]
    Access-Control-Expose-Headers: ['Docker-Content-Digest']
  http2:
    disabled: false
health:
  storagedriver:
    enabled: true
    interval: 10s
    threshold: 3
EOF

1.3 启动

cat > docker-compose.yaml <<EOF
version: '2.0'
services:
  registry:
    image: registry:2.7.1
    ports:
      - 5000:5000
    volumes:
      - /opt/registry:/var/lib/registry
      - /etc/docker/registry/config.yml:/etc/docker/registry/config.yml
  ui:
    image: joxit/docker-registry-ui:latest
    ports:
      - 80:80
    environment:
      - REGISTRY_TITLE=My Private Docker Registry
      - REGISTRY_URL=http://192.168.80.200:5000
      - SINGLE_REGISTRY=true
    depends_on:
      - registry
EOF

docker-compose up -d

1.4 镜像推送

$ docker tag nginx 192.168.80.200:5000/nginx:latest

$ docker push 192.168.80.200:5000/nginx:latest
The push refers to repository [192.168.80.200:5000/nginx]
Get "https://192.168.80.200:5000/v2/": http: server gave HTTP response to HTTPS client

# 开启非安全认证
$ vi /etc/docker/daemon.json
{
  "insecure-registries" : [ "192.168.80.250:5000" ]
}

$ systemctl restart docker

1.5 登录界面

http://192.168.80.200

1.6 Restful API

参考:https://docs.docker.com/registry/spec/api/#detail

# API Version Check
$ curl 192.168.80.200:5000/v2/
{}

# Listing Repositories
$ curl 192.168.80.200:5000/v2/_catalog
{"repositories":["nginx"]}

# Listing Image Tags
$ curl 192.168.80.200:5000/v2/nginx/tags/list
{"name":"nginx","tags":["latest"]}

# Fetch the manifest by tag
$ curl 192.168.80.200:5000/v2/nginx/manifests/latest

# 获取镜像的digest
$ curl -I 192.168.80.200:5000/v2/nginx/manifests/latest -H 'Accept: application/vnd.docker.distribution.manifest.v2+json'
...
Docker-Content-Digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3

# Deleting an Image by digest, not supported by tag (只是删除了相关的tag,但文件实体并未删除)
$ curl -X DELETE 192.168.80.200:5000/v2/nginx/manifests/sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3

# 清理磁盘,是否已被删除的 blob 数据
$ docker exec -it docker-registry bin/registry garbage-collect /etc/docker/registry/config.yml

2. Harbor

VMware 出品,优点:大而全;缺点:过于庞大,安装很多组件,如redis, nginx,较耗资源

2.1 生成证书

mkdir -p /etc/harbor/pki && cd $_

# CA
openssl req \
    -newkey rsa:4096 -nodes -sha256 -keyout ca.key \
    -x509 -days 365 -out ca.crt \
    -subj "/C=CN/ST=Jiangsu/L=Nanjing/O=XTWL/OU=IT/CN=test"
    
# 签名
openssl req \
    -newkey rsa:4096 -nodes -sha256 -keyout harbor.key \
    -out harbor.csr \
    -subj "/C=CN/ST=Jiangsu/L=Nanjing/O=XTWL/OU=IT/CN=192.168.80.201"
    
# 生成证书
echo 'subjectAltName = IP:192.168.80.201' > extfile.cnf
openssl x509 -req -days 365 -in harbor.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out harbor.crt

2.2 安装包

mkdir -p ~/harbor && cd $_
wget https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
tar xzvf harbor-offline-installer-v2.4.1.tgz

2.3 配置

cd harbor
cp harbor.yml.tmpl harbor.yml

vi harbor.yml
hostname: 192.168.80.201
http:
  port: 8080
https:
  port: 443
  certificate: /etc/harbor/pki/harbor.crt
  private_key: /etc/harbor/pki/harbor.key

harbor_admin_password: Harbor12345
data_volume: /data
location: /var/log/harbor

2.4 安装

./install.sh
...
[Step 5]: starting Harbor ...
[+] Running 10/10
 ⠿ Network harbor_harbor        Created    0.2s
 ⠿ Container harbor-log         Started    1.6s
 ⠿ Container registryctl        Started    3.7s
 ⠿ Container registry           Started    3.0s
 ⠿ Container redis              Started    3.3s
 ⠿ Container harbor-portal      Started    3.7s
 ⠿ Container harbor-db          Started    3.6s
 ⠿ Container harbor-core        Started    4.8s
 ⠿ Container harbor-jobservice  Started    6.2s
 ⠿ Container nginx              Started    6.5s
✔ ----Harbor has been installed and started successfully.----

2.5 Docker 配置

dockerd 进程会将.crt文件标记为CA证书,.cert文件为客户端证书,所以需要先进行转换

cd /etc/harbor/pki
openssl x509 -inform PEM -in harbor.crt -out harbor.cert

mkdir -p /etc/docker/certs.d/192.168.80.201
cp harbor.cert /etc/docker/certs.d/192.168.80.201
cp harbor.key /etc/docker/certs.d/192.168.80.201
cp ca.crt /etc/docker/certs.d/192.168.80.201

systemctl restart docker

2.6 镜像推送

# 先登录
$ docker login https://192.168.80.201
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

# 推送镜像
$ docker tag busybox:latest 192.168.80.201/library/busybox:latest
$ docker push 192.168.80.201/library/busybox:latest
The push refers to repository [192.168.80.201/library/busybox]
01fd6df81c8e: Pushed
latest: digest: sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee size: 527

2.7 登录界面

https://192.168.80.201 admin/Harbor12345

3. nexus3

可作为 docker , maven , yum, apt, PyPInpm, go proxy 等私有仓库或代理。

3.1 安装

$ mkdir -p /opt/nexus3 && chown -R 200 /opt/nexus3
$ docker run -d --name nexus3 --restart=always -p 8081:8081 -v /opt/nexus3:/nexus-data sonatype/nexus3
    
$ docker logs -f nexus3
...
Started Sonatype Nexus OSS 3.37.3-02

3.2 登录

# 获取密码
$ docker exec nexus3 cat /nexus-data/admin.password
ac686e08-008c-4f60-aaf3-17a7bea079a1

# 登录并修改密码
http://192.168.80.200:8081  admin/ac686e08-008c-4f60-aaf3-17a7bea079a1

# 按向导修改密码,并开启匿名登录
admin/admin123

3.3 创建仓库

创建一个私有仓库的方法: Repository->Repositories 点击右边菜单 Create repository 选择 docker (hosted)

  • Name: 仓库的名称
  • HTTP: 仓库单独的访问端口(例如:8082
  • Hosted -> Deplioyment policy: 请选择 Allow redeploy 否则无法上传 Docker 镜像。

3.4 添加访问权限

菜单 Security->Realms 把 Docker Bearer Token Realm 移到右边的框中保存。

添加用户规则:菜单 Security->Roles->Create rolePrivlleges 选项搜索 docker 把相应的规则移动到右边的框中然后保存。

添加用户:菜单 Security->Users->Create local userRoles 选项中选中刚才创建的规则移动到右边的窗口保存。

3.5 开放端口

# docker 配置
$ vi /etc/docker/daemon.json 
{
  "insecure-registries" : [ "192.168.80.200:8082" ]
}
$ systemctl restart docker

# 服务IP
$ docker inspect nexus3 | grep -w IPAddress
"IPAddress": "172.17.0.2",

$ iptables -t nat -vnL
Chain POSTROUTING (policy ACCEPT 327 packets, 17060 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  all  --  *      !docker0  172.17.0.0/16        0.0.0.0/0
    0     0 MASQUERADE  all  --  *      !br-f2446e4164ee  172.20.0.0/16        0.0.0.0/0
    0     0 MASQUERADE  tcp  --  *      *       172.17.0.2           172.17.0.2           tcp dpt:8081

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  docker0 *       0.0.0.0/0            0.0.0.0/0
    0     0 RETURN     all  --  br-f2446e4164ee *       0.0.0.0/0            0.0.0.0/0
  326 16984 DNAT       tcp  --  !docker0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8081 to:172.17.0.2:8081

# 新增
iptables -t nat -A  DOCKER -p tcp --dport 8082 -j DNAT --to-destination 172.17.0.2:8082
iptables -t nat -A  DOCKER -p tcp ! -i docker0 --dport 8082 -j DNAT --to-destination 172.17.0.2:8082

# 端口列表
$ iptables -t nat -vnL DOCKER --line-number
Chain DOCKER (2 references)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 RETURN     all  --  docker0 *       0.0.0.0/0            0.0.0.0/0
2        0     0 RETURN     all  --  br-f2446e4164ee *       0.0.0.0/0            0.0.0.0/0
3       25  1300 DNAT       tcp  --  !docker0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8081 to:172.17.0.2:8081
4        0     0 DNAT       tcp  --  !docker0 *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8082 to:172.17.0.2:8082

# 删除 (需要时)
iptables -t nat -D DOCKER 4

3.6 镜像管理

# 登录仓库
$ docker login http://192.168.80.200:8082
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

# 上传镜像
$ docker tag busybox:latest 192.168.80.200:8082/repository/xtwl/busybox:latest
$ docker push 192.168.80.200:8082/repository/xtwl/busybox:latest
The push refers to repository [192.168.80.200:8082/repository/xtwl/busybox]
01fd6df81c8e: Pushed
latest: digest: sha256:62ffc2ed7554e4c6d360bce40bbcf196573dd27c4ce080641a2c59867e732dee size: 527
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker 私有仓库 的相关文章

  • java for循环的几种写法

    参考 xff1a https blog csdn net qq 36804363 article details 87539927 span class token keyword int span span class token pun
  • 【双指针】和为S的两个数字

    题目描述 输入一个递增排序的数组和一个数字S xff0c 在数组中查找两个数 xff0c 使得他们的和正好是S xff0c 如果有多对数字的和等于S xff0c 输出两个数的乘积最小的 输入 1 2 4 7 11 15 15 返回值 4 1
  • 【动态规划】连续子数组的最大和

    题目描述 输入一个整型数组 xff0c 数组里有正数也有负数 数组中的一个或连续多个整数组成一个子数组 求所有子数组的和的最大值 要求时间复杂度为 O n 输入 xff1a 1 2 3 10 4 7 2 5 返回值 xff1a 18 说明
  • Java交换字符串中两个位置的值

    需求 xff1a 对一字符串abcd xff0c 要求交换位置0和位置2的两个字符 xff0c 交换结果为cbad java高效实现方案 xff0c 先将String转换为char数组 xff0c 数组可以修改任意位置的值 xff0c 进行
  • 【动态规划、递归回溯】字符串的排列

    题目描述 输入一个字符串 按字典序打印出该字符串中字符的所有排列 例如输入字符串abc 则按字典序打印出由字符a b c所能排列出来的所有字符串abc acb bac bca cab和cba 输入一个字符串 长度不超过9 可能有字符重复 字
  • 【数组】把数组排成最小的数

    题目描述 输入一个正整数数组 xff0c 把数组里所有数字拼接起来排成一个数 xff0c 打印能拼接出的所有数字中最小的一个 例如输入数组 3 xff0c 32 xff0c 321 xff0c 则打印出这三个数字能排成的最小数字为32132
  • Docker 容器介绍

    1 简介 1 1 容器和VM 什么是容器 xff1a 一种操作系统级别的虚拟化的方案只能运行相同或相似内核的操作系统依赖Linux内核特性 xff1a Namespace和Cgroups 1 2 依赖内核特性 Namespaces xff1
  • 【数组】数组中重复的数字

    题目描述 在一个长度为n的数组里的所有数字都在0到n 1的范围内 数组中某些数字是重复的 xff0c 但不知道有几个数字是重复的 也不知道每个数字重复几次 请找出数组中第一个重复的数字 例如 xff0c 如果输入长度为7的数组 2 3 1
  • 【数组】构建乘积数组

    题目描述 给定一个数组A 0 1 n 1 请构建一个数组B 0 1 n 1 其中B中的元素B i 61 A 0 A 1 A i 1 A i 43 1 A n 1 不能使用除法 xff08 注意 xff1a 规定B 0 61 A 1 A 2
  • 【二分法】数字在升序数组中出现的次数

    题目描述 统计一个数字在升序数组中出现的次数 示例1 输入 1 2 3 3 3 3 4 5 3 返回值 4 看到数组是有序的 xff0c 并且是查找 xff0c 应该想到用二分法 xff0c 最简单的方法是用二分法找到该数 xff0c 然后
  • 【字符串】第一个只出现一次的字符

    题目描述 在一个字符串 0 lt 61 字符串长度 lt 61 10000 xff0c 全部由字母组成 中找到第一个只出现一次的字符 并返回它的位置 如果没有则返回 1 xff08 需要区分大小写 xff09 xff08 从0开始计数 xf
  • 【字符串】左旋转字符串

    题目描述 汇编语言中有一种移位指令叫做循环左移 xff08 ROL xff09 xff0c 现在有个简单的任务 xff0c 就是用字符串模拟这个指令的运算结果 对于一个给定的字符序列S xff0c 请你把其循环左移K位后的序列输出 例如 x
  • 【字符串】翻转单词顺序列

    题目描述 牛客最近来了一个新员工Fish xff0c 每天早晨总是会拿着一本英文杂志 xff0c 写些句子在本子上 同事Cat对Fish写的内容颇感兴趣 xff0c 有一天他向Fish借来翻看 xff0c 但却读不懂它的意思 例如 xff0
  • 【数组】扑克牌顺子

    题目描述 LL今天心情特别好 因为他去买了一副扑克牌 发现里面居然有2个大王 2个小王 一副牌原本是54张 他随机从中抽出了5张牌 想测测自己的手气 看看能不能抽到顺子 如果抽到的话 他决定去买体育彩票 嘿嘿 xff01 xff01 红心A
  • 【torch.einsum】

    参考 xff1a https www cnblogs com mengnan p 10319701 html 爱因斯坦简记法 xff0c 能简洁表示各种矩阵向量的操作 xff0c 例如矩阵转置 乘法 求和等等 xff0c pytorch中调
  • Linux关闭指定GPU进程

    首先查看正在运行的GPU进程 span class token function watch span n 1 nvidia smi 查看GPU进程PID 使用命令kill 9 PID关闭进程 xff0c 多个进程则PID之间用空格隔开 x
  • 【字符串】字符流中第一个不重复的字符

    题目描述 请实现一个函数用来找出字符流中第一个只出现一次的字符 例如 xff0c 当从字符流中只读出前两个字符 34 go 34 时 xff0c 第一个只出现一次的字符是 34 g 34 当从该字符流中读出前六个字符 google 34 时
  • Docker 镜像和容器

    1 安装配置 1 1 安装 span class token comment 卸载 span span class token function sudo span span class token function apt span re
  • 【字符串】表示数值的字符串

    题目描述 请实现一个函数用来判断字符串是否表示数值 xff08 包括整数和小数 xff09 例如 xff0c 字符串 34 43 100 34 5e2 34 123 34 3 1416 34 和 1E 16 34 都表示数值 但是 34 1
  • linux 服务器安装 anaconda

    https www cnblogs com zwq zju p 9715162 html

随机推荐

  • Linux将文件夹下所有文件复制到另一个文件中

    cp r source file dest file xff0c 表示所有文件
  • 【字符串 递归】正则表达式匹配

    题目描述 请实现一个函数用来匹配包括 和 的正则表达式 模式中的字符 表示任意一个字符 xff0c 而 39 表示它前面的字符可以出现任意次 xff08 包含0次 xff09 在本题中 xff0c 匹配是指字符串的所有字符匹配整个模式 例如
  • 解决Linux下载较慢的问题

    修改源 xff0c 输入命令sudo gedit etc apt sources list xff0c 覆盖源文件中所有内容 deb http mirrors aliyun com ubuntu trusty main restricted
  • Linux配置ssh

    服务器主机安装ssh sudo apt get install openssh server xff0c 客户端使用putty等支持ssh的软件登录即可 xff0c 记住服务器的ip和密码
  • pytorch计算模型参数量

    total span class token operator 61 span span class token builtin sum span span class token punctuation span span class t
  • 【字符串】把字符串转换成整数

    题目描述 将一个字符串转换成一个整数 xff0c 要求不能使用字符串转换整数的库函数 数值为0或者字符串不是一个合法的数值则返回0 输入描述 输入一个字符串 包括数字字母符号 可以为空 返回值描述 如果是合法的数值表达则返回该数字 xff0
  • 【树】二叉树的镜像

    题目描述 操作给定的二叉树 xff0c 将其变换为源二叉树的镜像 思路很简单 xff0c 只需要递归遍历树 xff0c 然后将每个节点的左右子树调换即可 span class token keyword import span java s
  • 【树】树的子结构

    来自剑指offer 这题有点难度 xff0c 解题思想是 xff1a 若B是A的子树 xff0c 则子树的根节点可能为树A中的任意一个节点 xff0c 因此只需要遍历树A的每个节点 xff0c 判断以这个节点为根节点的树是否包含子树B xf
  • Docker 网络

    1 简介 容器网络实质上是由 Docker 为应用程序所创造的虚拟环境的一部分 xff0c 它能让应用从宿主机操作系统的网络环境中独立出来 xff0c 形成容器自有的网络设备 IP 协议栈 端口套接字 IP 路由表 防火墙等与网络相关的模块
  • Ubuntu 20安装Nvidia驱动 + cuda10.1 + Anaconda + pytorch 1.5

    安装Nvidia驱动 输入命令 ubuntu drivers devices查看显卡推荐的驱动选择recommend的版本进行安装 xff0c 例如我的是460 sudo apt install nvidia driver 460 安装完成
  • VScode ssh远程服务器解决试图写入的管道不存在

    解决方案 xff0c 在C盘用户目录下找到 ssh文件 xff0c 删除known hosts文件或打开known hosts删除对应的ip
  • S3DIS场景点云数据集

    S3DIS是常用的室内场景分割数据集 xff0c 包含6个Area xff0c 常用的数据格式如下 xff1a Stanford3dDataset v1 2 Aligned Version xff0c 百度网盘下载 xff0c 提取码0ac
  • jupyter远程连接服务器

    服务器终端输入命令 jupyter notebook no browser port 61 8889 本地终端输入命令 ssh N f L localhost 8888 localhost 8889 username 64 ip usern
  • win10远程Linux桌面

    在Linux服务器安装xrdp xff1a sudo apt install xrdp win10远程 xff0c win 43 R xff0c 输入mstsc xff0c 输入linux服务器ip和账户 具体参考 https www ma
  • python控制输出精度

    a span class token operator 61 span span class token number 3 1456 span b span class token operator 61 span span class t
  • 多分类混淆矩阵的理解

    借用其它博客的一张例子示意图 xff0c 该图为一个三分类问题的混淆矩阵 xff0c 对角线的值表示分类器对该类别预测正确的个数 xff0c 每一列纵轴表示这个类别真实的样本数 xff0c 例如从第一列可以得知猫一共有10 43 3 43
  • ERROR: Could not find a version that satisfies the requirement dateutil

    安装dateutil出错 xff0c 提示 ERROR Could not find a version that satisfies the requirement dateutil 解决办法 xff1a pip install pyth
  • RTX3090 + cuda 11.1 + torch1.9.0 安装 MinkowskiEngine

    创建conda环境 conda create n mink span class token assign left variable python span span class token operator 61 span span c
  • pytorch更新tensor中指定index位置的值scatter_add_

    使用scatter add 更新tensor张量中指定index位置的值 例子 span class token keyword import span torch a span class token operator 61 span t
  • Docker 私有仓库

    1 Registry 官方私有仓库 xff0c 优点 xff1a 简单 xff1b 缺点 xff1a 部署无法进行复杂的管理操作 1 1 镜像 docker pull registry 2 7 1 docker pull joxit doc