Docker-安装私服

Posted guardwhy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker-安装私服相关的知识,希望对你有一定的参考价值。

在使用maven管理jar包依赖的时候,为了避免每次都从中央仓库拉取依赖包,使用了nexus做了代理仓库。docker镜像仓库与nexus私服仓库作用类似,用于将打包好的镜像保存在仓库中方便开发、测试、生产环境镜像拉取存储,减轻环境部署需要的相应操作。

1.1 购买阿里云服务器

1、选择云服务器,创建实例

2、自定义购买,按量付费

3、选择服务器类型,数量,内存,带宽



4、自定义登录密码

5、创建成功!!!

1.2 节点信息

购买两个服务器,服务器的名字为root,服务器密码: Hxy162530

主机名ip地址具体说明
guardwhy018.134.117.200docker主机
guardwhy028.134.113.78registry主机

1.3 官方私服

1、镜像官方地址: https://hub.docker.com/_/registry

2、基础镜像

拉取基本镜像

docker pull registry:2.7.1

运行容器

docker run -itd --name gegistry -p 5000:5000 --restart always registry:2.7.1


访问链接: http://8.134.113.78:5000/v2/_catalog

3、添加私服仓库地址

编辑配置文件
vim /etc/docker/daemon.json

增加仓库配置信息
 "insecure-registries":["8.134.113.78:5000"] 

重启docker
systemctl daemon-reload
systemctl restart docker

查看docker信息确认仓库是否添加
docker info


4、上传镜像

docker tag nginx:1.20.1 8.134.113.78:5000/nginx:v1
docker push 8.134.113.78:5000/nginx:v1


5、查看镜像版本和信息

6、从官方私服中下载镜像

[root@guardwhy01 ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@guardwhy01 ~]# docker pull 8.134.113.78:5000/nginx:v1
v1: Pulling from nginx
69692152171a: Pull complete 
94d185f62f0a: Pull complete 
da9d3d3df3e3: Pull complete 
1c11b8f3980d: Pull complete 
541b1d41bb91: Pull complete 
d8f6ef04dfa8: Pull complete 
Digest: sha256:56cbb3c9ada0858d69d19415039ba2aa1e9b357ba9aa9c88c73c30307aae17b0
Status: Downloaded newer image for 8.134.113.78:5000/nginx:v1
8.134.113.78:5000/nginx:v1
[root@guardwhy01 ~]# docker images
REPOSITORY                TAG       IMAGE ID       CREATED       SIZE
8.134.113.78:5000/nginx   v1        993ef3592f66   3 weeks ago   133MB
[root@guardwhy01 ~]# 

1.4 企业私服

1.4.1 安装私服

1、购买2核8G内存服务器,安装dockerdocker compose

2、下载harbor

官方地址: https://goharbor.io/

github官网地址:https://github.com/goharbor/harbor

官方帮助文档:https://github.com/goharbor/harbor/blob/v1.9.4/docs/installation_guide.md

3、服务器配置

硬件资源最小配置推荐配置
CPU2CPU4CPU
内存4GB8GB
硬盘40GB60GB

4、安装harbor开发环境大部分采用http方式进行安装,推荐使用离线安装!!!

通过Xftp上传到\\home\\data目录中,然后解压软件。

[root@guardwhy03 data]# ls
harbor-offline-installer-v1.9.4.tgz
[root@guardwhy03 data]# tar zxvf harbor-offline-installer-v1.9.4.tgz 
harbor/harbor.v1.9.4.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml
[root@guardwhy03 data]# ll
total 624500
drwxr-xr-x 2 root root      4096 Jun 17 21:53 harbor
-rw-r--r-- 1 root root 639477963 Jun 17 21:11 harbor-offline-installer-v1.9.4.tgz

5、进入安装目录,修改harbor.yml文件

修改私服镜像地址

hostname: 8.134.123.77

修改镜像地址访问端口号

port: 5000


harbor管理员登录系统密码

harbor_admin_password: Harbor12345


修改harbor映射卷目录

data_volume: /home/data/harbor


5、安装harbor

执行启动脚本

./install.sh

准备安装环境:检查docker版本和docker-compose版本

安装成功!!!

6、使用Chrome 浏览器访问harbor私服,点击链接: http://8.134.123.77:5000/harbor/projects,输入用户名和默认的密码

1.4.2 上传镜像

1、在主机docker01中配置私服。

[root@guardwhy01 data]# vim /etc/docker/daemon.json
[root@guardwhy01 data]# cat /etc/docker/daemon.json

  "registry-mirrors": ["https://5bsomu6l.mirror.aliyuncs.com"],
  "insecure-registries":["8.134.123.77:5000"]

## 重启docker服务!!!
[root@guardwhy01 data]# systemctl daemon-reload
[root@guardwhy01 data]# systemctl restart docker

2、在harbor界面中新建项目:guardwhy_cms

3、登录和退出私服

## 登录私服
docker login -u admin -p Harbor12345 8.134.123.77:5000

## 退出私服
docker logout 8.134.123.77:5000


查看当前镜像

[root@guardwhy01 data]# docker images
REPOSITORY   TAG                  IMAGE ID       CREATED       SIZE
nginx        1.20.1               993ef3592f66   3 weeks ago   133MB
tomcat       9.0.20-jre8-alpine   387f9d021d3a   2 years ago   108MB

4、上传镜像

docker tag nginx:1.20.1 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
docker tag tomcat:9.0.20-jre8-alpine 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0

## 推送操作
docker push 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
docker push 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0

查看镜像


上传镜像成功!!

5、通过私服下载镜像,下载成功!!!

[root@guardwhy01 data]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@guardwhy01 data]# docker pull 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
v1.0: Pulling from guardwhy_cms/nginx
69692152171a: Pull complete 
94d185f62f0a: Pull complete 
da9d3d3df3e3: Pull complete 
1c11b8f3980d: Pull complete 
541b1d41bb91: Pull complete 
d8f6ef04dfa8: Pull complete 
Digest: sha256:56cbb3c9ada0858d69d19415039ba2aa1e9b357ba9aa9c88c73c30307aae17b0
Status: Downloaded newer image for 8.134.123.77:5000/guardwhy_cms/nginx:v1.0
8.134.123.77:5000/guardwhy_cms/nginx:v1.0
[root@guardwhy01 data]# docker pull 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
v1.0: Pulling from guardwhy_cms/tomcat
e7c96db7181b: Pull complete 
f910a506b6cb: Pull complete 
b6abafe80f63: Pull complete 
d8c966ddef98: Pull complete 
15b754e99755: Pull complete 
4227393eb352: Pull complete 
Digest: sha256:490b98379033031e84f9795da326371fdb95c6d9c3f5e3c14e1316ca754e324f
Status: Downloaded newer image for 8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
8.134.123.77:5000/guardwhy_cms/tomcat:v1.0
[root@guardwhy01 data]# docker images
REPOSITORY                              TAG       IMAGE ID       CREATED       SIZE
8.134.123.77:5000/guardwhy_cms/nginx    v1.0      993ef3592f66   3 weeks ago   133MB
8.134.123.77:5000/guardwhy_cms/tomcat   v1.0      387f9d021d3a   2 years ago   108MB
[root@guardwhy01 data]# 

以上是关于Docker-安装私服的主要内容,如果未能解决你的问题,请参考以下文章

Docker 环境下搭建nexus私服

linux上Docker安装gogs私服亲测(详解)

Docker-安装私服

Docker-安装私服

Docker 私服Registry简介与使用Docker-Compose安装Registry

linux上Docker安装gogs私服