Docker部署私有仓库

简介:

今天和大家聊聊Docker的私有仓库。

前段时间啊在CentOS6.x上玩Docker的私有仓库,由于https认证的原因,一直没有能解决,最后听群上的一朋友说,换成CentOS 7试试,也别说,最后实验成功啦!

所以我建议朋友在玩docker的私有仓库的时候,也能现在CentOS7.x系统上玩,确定对整个过程熟悉后,然后换成你熟悉的6.x的系统,这样也是一个循循渐进的过程吧!


一、准备

1、地址规划

1
2
Docker私有仓库地址:192.168.0.109
Docker客户端地址:192.168.0.110

2、激活网卡

1
2
3
4
# vim /etc/sysconfig/network-scripts/ifcfg-eno16777728
修改此行
ONBOOT= yes
# /etc/init.d/network restart

3、关闭本地防火墙并设置开机不自启动

1
2
# systemctl stop firewalld.service
# systemctl disable firewalld.service

4、关闭本地selinux防火墙

1
2
3
# vi /etc/sysconfig/selinux 
SELINUX=disabled
# setenforce 0   

5、安装ifconfig工具

1
# yum install net-tools


二、安装

1、安装docker

1
2
3
4
# yum install docker
# yum upgrade device-mapper-libs
# service docker start
# chkconfig docker on

2、本地私有仓库registry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost ~] # docker pull registry
Trying to pull repository docker.io /registry  ...
24dd746e9b9f: Download complete 
706766fe1019: Download complete 
a62a42e77c9c: Download complete 
2c014f14d3d9: Download complete 
b7cf8f0d9e82: Download complete 
d0b170ebeeab: Download complete 
171efc310edf: Download complete 
522ed614b07a: Download complete 
605ed9113b86: Download complete 
22b93b23ebb9: Download complete 
2ac557a88fda: Download complete 
1f3b4c532640: Download complete 
27ebaac643a7: Download complete 
ce630195cb45: Download complete 
Status: Downloaded newer image  for  docker.io /registry :latest
[root@localhost ~] # docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io /registry    latest              24dd746e9b9f        3 days ago          413.8 MB

3、基于私有仓库镜像运行容器

1
2
3
4
5
[root@localhost ~] # docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry docker.io/registry
bb2c0d442df94e281479332c2608ef144f378e71743c5410e36b80c465771a95
[root@localhost ~] # docker ps -a
CONTAINER ID        IMAGE                       COMMAND             CREATED             STATUS              PORTS                    NAMES
bb2c0d442df9        docker.io /registry :latest    "docker-registry"    10 seconds ago      Up 7 seconds        0.0.0.0:5000->5000 /tcp    serene_hopper

4、访问私有仓库

1
2
[root@localhost ~] # curl 127.0.0.1:5000/v1/search
{ "num_results" : 0,  "query" "" "results" : []}  // 私有仓库为空,没有提交新镜像到仓库中

5、从Docker Hub上下载一个ssh镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost ~] # docker search -s 10 ssh
NAME                              DESCRIPTION   STARS     OFFICIAL   AUTOMATED
docker.io: docker.io /fedora/ssh                  18                   [OK]
[root@localhost ~] # docker pull fedora/ssh
Trying to pull repository docker.io /fedora/ssh  ...
2aeb2b6d9705: Download complete 
511136ea3c5a: Download complete 
00a0c78eeb6d: Download complete 
834629358fe2: Download complete 
571e8a51403c: Download complete 
87d5d42e693c: Download complete 
92b5ef05fe68: Download complete 
92d3910dc33c: Download complete 
cf2e9fa11368: Download complete 
Status: Downloaded newer image  for  docker.io /fedora/ssh :latest
[root@localhost ~] # docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io /registry      latest              24dd746e9b9f        3 days ago          413.8 MB
docker.io /fedora/ssh    latest              2aeb2b6d9705        9 days ago          254.4 MB

6、创建镜像链接或为基础镜像打个标签

1
2
3
4
5
6
[root@localhost ~] # docker tag docker.io/fedora/ssh 127.0.0.1:5000/ssh
[root@localhost ~] # docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io /registry      latest              24dd746e9b9f        3 days ago          413.8 MB
docker.io /fedora/ssh    latest              2aeb2b6d9705        9 days ago          254.4 MB
127.0.0.1:5000 /ssh      latest              2aeb2b6d9705        9 days ago          254.4 MB

7、修改Docker配置文件制定私有仓库url

1
2
3
4
5
[root@localhost ~] # vim /etc/sysconfig/docker
修改此行
OPTIONS= '--selinux-enabled --insecure-registry 192.168.0.109:5000'
[root@localhost ~] # service docker restart
Redirecting to  /bin/systemctl  restart  docker.service

8、提交镜像到本地私有仓库中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost ~] # docker push 127.0.0.1:5000/ssh
The push refers to a repository [127.0.0.1:5000 /ssh ] (len: 1)
Sending image list
Pushing repository 127.0.0.1:5000 /ssh  (1 tags)
511136ea3c5a: Image successfully pushed 
00a0c78eeb6d: Image successfully pushed 
834629358fe2: Image successfully pushed 
571e8a51403c: Image successfully pushed 
87d5d42e693c: Image successfully pushed 
92b5ef05fe68: Image successfully pushed 
92d3910dc33c: Image successfully pushed 
cf2e9fa11368: Image successfully pushed 
2aeb2b6d9705: Image successfully pushed 
Pushing tag  for  rev [2aeb2b6d9705] on {http: //127 .0.0.1:5000 /v1/repositories/ssh/tags/latest }

9、查看私有仓库是否存在对应的镜像

1
2
[root@localhost ~] # curl 127.0.0.1:5000/v1/search
{ "num_results" : 1,  "query" "" "results" : [{ "description" "" "name" "library/ssh" }]}

10、查看镜像的存储目录和文件

1
2
3
4
5
6
7
8
9
10
[root@localhost ~] # tree /opt/data/registry/repositories/
/opt/data/registry/repositories/
└── library
     └──  ssh
         ├── _index_images
         ├── json
         ├── tag_latest
         └── taglatest_json
 
2 directories, 4 files


三、从私有仓库中下载已有的镜像

1、登陆另外一台Docker客户端

1
2
3
4
5
6
7
[root@localhost ~] # ssh root@192.168.0.110
The authenticity of host  '192.168.0.110 (192.168.0.110)'  can't be established.
ECDSA key fingerprint is 5b:81:4b:66:d6: dd :48:16:9f:85:58:72:21:bd:ba:39.
Are you sure you want to  continue  connecting ( yes /no )?  yes
Warning: Permanently added  '192.168.0.110'  (ECDSA) to the list of known hosts.
root@192.168.0.110's password: 
Last login: Sun Apr 26 14:39:51 2015 from 192.168.0.103

2、修改Docker配置文件

1
2
3
4
5
[root@localhost ~] # vim /etc/sysconfig/docker
修改此行
OPTIONS= '--selinux-enabled --insecure-registry 192.168.0.109:5000'         // 添加私有仓库地址
[root@localhost ~] # service docker restart
Redirecting to  /bin/systemctl  restart  docker.service

3、从私有仓库中下载已有的镜像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost ~] # docker pull 192.168.0.109:5000/ssh
Trying to pull repository 192.168.0.109:5000 /ssh  ...
2aeb2b6d9705: Download complete 
511136ea3c5a: Download complete 
00a0c78eeb6d: Download complete 
834629358fe2: Download complete 
571e8a51403c: Download complete 
87d5d42e693c: Download complete 
92b5ef05fe68: Download complete 
92d3910dc33c: Download complete 
cf2e9fa11368: Download complete 
Status: Downloaded newer image  for  192.168.0.109:5000 /ssh :latest
[root@localhost ~] # docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
192.168.0.109:5000 /ssh    latest              2aeb2b6d9705        9 days ago          254.4 MB


四、浏览器访问仓库

wKioL1U8yD2CICJXAACRXA3Ij1w707.jpg




     本文转自zys467754239 51CTO博客,原文链接:http://blog.51cto.com/467754239/1638770,如需转载请自行联系原作者



相关文章
|
12天前
|
Ubuntu 安全 Docker
Ubuntu下部署及操作Docker技巧
以上就是在Ubuntu下部署及操作Docker的具体步骤。但这只是冰山一角,Docker的魅力远不仅如此。你可以将其视为存放各种工具的小箱子,随时随地取用,极大地提升工作效率。你也可以私人订制,适应不同的开发环境,就像一个拥有各种口味冰淇淋的冰箱,满足各种各样的需求。好了,现在你已经掌握了基本的Docker运用技巧,快去尝试使用吧!记住,沉浸在探索中,你会找到无尽的乐趣和满满的收获。
70 23
|
19天前
|
存储 SQL 关系型数据库
docker部署n9e开源版本7.4.0
n9e开源版本7.4.0
36 0
|
22天前
|
安全 API 算法框架/工具
大模型文件Docker镜像化部署技术详解
大模型文件Docker镜像化部署技术详解
168 2
|
1月前
|
JSON 运维 Ubuntu
在Docker上部署Ollama+AnythingLLM完成本地LLM Agent部署
通过以上步骤,您可以成功在Docker上部署Ollama和AnythingLLM,实现本地LLM Agent的功能。在部署过程中,确保环境和配置正确,以避免不必要的问题。希望本文能够帮助您顺利完成部署,并在本地环境中高效地使用LLM模型。
581 8
|
1月前
|
Docker Python 容器
Docker——阿里云服务器使用Docker部署python项目全程小记
本文记录了我在阿里云服务器上使用Docker部署python项目(flask为例)的全过程,在这里记录和分享一下,希望可以给大家提供一些参考。
158 0
|
1月前
|
Linux 虚拟化 Docker
Linux服务器部署docker windows
在当今软件开发中,Docker成为流行的虚拟化技术,支持在Linux服务器上运行Windows容器。流程包括:1) 安装Docker;2) 配置支持Windows容器;3) 获取Windows镜像;4) 运行Windows容器;5) 验证容器状态。通过这些步骤,你可以在Linux环境中顺利部署和管理Windows应用,提高开发和运维效率。
165 1
|
2月前
|
中间件 关系型数据库 数据库
docker快速部署OS web中间件 数据库 编程应用
通过Docker,可以轻松地部署操作系统、Web中间件、数据库和编程应用。本文详细介绍了使用Docker部署这些组件的基本步骤和命令,展示了如何通过Docker Compose编排多容器应用。希望本文能帮助开发者更高效地使用Docker进行应用部署和管理。
81 19
|
2月前
|
人工智能 文字识别 安全
Stirling-PDF:51.4K Star!用Docker部署私有PDF工作站,支持50多种PDF操作,从此告别在线工具
Stirling-PDF 是一款基于 Docker 的本地化 PDF 编辑工具,支持 50 多种 PDF 操作,包括合并、拆分、转换、压缩等,同时提供多语言支持和企业级功能,满足个人和企业用户的多样化需求。
144 6
Stirling-PDF:51.4K Star!用Docker部署私有PDF工作站,支持50多种PDF操作,从此告别在线工具
|
2月前
|
消息中间件 监控 RocketMQ
Docker部署RocketMQ5.2.0集群
本文详细介绍了如何使用Docker和Docker Compose部署RocketMQ 5.2.0集群。通过创建配置文件、启动集群和验证容器状态,您可以快速搭建起一个RocketMQ集群环境。希望本文能够帮助您更好地理解和应用RocketMQ,提高消息中间件的部署和管理效率。
340 91
|
2月前
|
存储 NoSQL Redis
Docker 部署 Redis
在使用 Docker 部署 Redis 时,为实现数据持久化,需正确挂载容器内的数据目录到宿主机。推荐命令如下: ``` docker run -d --name redis -v /mnt/data/redis:/data -p 6379:6379 redis ``` 该命令将宿主机的 `/mnt/data/redis` 目录挂载到容器的 `/data` 目录,确保 Redis 数据持久化。此路径更通用,适合大多数场景。避免使用不匹配的挂载路径,如 `/var/lib/redis` 或 `/mnt/data/redis` 到非默认目录,以防止数据无法正确持久化。