安装Nexus Nexus是Sonatype提供的仓库管理平台,Nuexus Repository OSS3能够支持Maven、npm、Docker、YUM、Helm等格式数据的存储和发布;并且能够与Jekins、SonaQube和Eclipse等工具进行集成。
查看docker 并安装docker 启动docker服务
[root@localhost yum.repos.d]# yum list docker-ce.x86_64 --showduplicates | sort -r
已加载插件:fastestmirror, langpacks
可安装的软件包
Loading mirror speeds from cached hostfile
docker-ce.x86_64 3:20.10.5-3.el7 docker
docker-ce.x86_64 3:20.10.5-3.el7 docker
docker-ce.x86_64 3:19.03.13-3.el7 docker
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# yum install docker-ce.x86_64 3:20.10.5-3.el7 -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
.....
.....
.....
[root@localhost yum.repos.d]# systemctl start docker
创建目录nexus
[root@localhost /]# mkdir /home/nexus-data && chown -R 200 /home/nexus-data
pull sonatype/nexus3 镜像
[root@localhost /]# docker run -d --name nexus3 --restart=always -p 8081:8081 -p 8082:8082 -v /home/nexus-data:/nexus-data sonatype/nexus3
Unable to find image 'sonatype/nexus3:latest' locally
latest: Pulling from sonatype/nexus3
1b890c73c3cf: Pull complete
de63ba066b7c: Pull complete
b96fec3b344c: Pull complete
9139abc9b143: Pull complete
Digest: sha256:4267d43f2fd71d2f70f210fe6a5a21eb4db2f2079f9cf8008f66194221d68cc6
Status: Downloaded newer image for sonatype/nexus3:latest
caa930455d0676bf382558a2342a9f11caa5897993846b1cc4ee039d0bb193f8
[root@localhost /]#
参数说明
-d:在容器中打开一个伪终端进行交互操作,并在后台运行
-v:把宿主机的/root/nexus-data目录挂载到容器/var/nexus-data目录,来实现数据的持久化
-p:映射端口,访问宿主机的8081端口就访问到nexus容器的服务了
--restart=always:这是重启的策略,假如这个容器异常退出会自动重启容器
--name nexus:创建容器命名为nexus,你可以随便命名
sonatype/nexus3:pull下来的镜像
访问nexus
在浏览器输入:http://ip:8081即可看到以下页面:(ip为远程主机的ip地址)
构建私有镜像仓库
在nexus部署成功后,在浏览器中通过http://{host_ip}:8081地址访问nexus应用。通过管理员帐户登录admin,
[root@localhost /]# find / -name 'admin.password'
/home/nexus-data/admin.password
[root@localhost /]# cd /home/nexus-data/
[root@localhost nexus-data]# cat admin.password
dc334427-c688-4978-b005-01fdc5266c55
更改密码
设置 匿名用户登陆允许与不允许
admin登陆成功
先创建Blos Store
创建为docker的镜像仓库的主页
在创建镜像仓库的页面中,设置镜像仓库的相关信息,包括名称、HTTP端口、是否允许匿名拉取镜像等信息。这里需要注意的是,此处的HTTP端口(此处的值为1008)很重要,后续拉取和推送进行是使用此端口进行的,而不是nexus本身对外暴露的端口。另外,如果允许设置通过匿名的方式拉取镜像。
点击 Create repository 创建仓库
选docker(hosted)
group 代表组的概念
hosted 代表本地仓库
proxy 代表代理库
创建docker成功
配置私有仓库地址
vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.100.201:8082"]
}
重启dockers服务
[root@localhost /]# systemctl restart docker
通过ip登录nexus的docker仓库:
root@localhost /]# docker login -u admin -p admin123 192.168.100.201:8082
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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
外网拉取一个nginx镜像 然后打包上传到仓库里
[root@localhost /]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
461246efe0a7: Pull complete
a96aaf9a9ec3: Pull complete
650d8b758441: Pull complete
b138da793ac8: Pull complete
bb1705539683: Pull complete
b9ed43dcc388: Pull complete
Digest: sha256:dbe677093f569cc0afe2a149c529645f255aac959490ef11fb19ac6418b815d3
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost /]# docker tag nginx 192.168.100.201:8082/nginx:latest
[root@localhost /]# docker push 192.168.100.201:8082/nginx:latest
The push refers to repository [192.168.100.201:8082/nginx]
de100bd247e0: Pushed
1d561d938628: Pushed
c03189a5ef70: Pushed
305b0db3a210: Pushed
1c99a7efe9d9: Pushed
43b3c4e3001c: Pushed
latest: digest: sha256:33cef86aae4e8487ff23a6ca16012fac28ff9e7a5e9759d291a7da06e36ac958 size: 1570
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.100.201:8082/nginx latest 41b0e86104ba 28 hours ago 142MB
nginx latest 41b0e86104ba 28 hours ago 142MB
sonatype/nexus3 latest be6da324b885 2 weeks ago 691MB
删除本地拉取的nginx镜像
[root@localhost /]# docker rmi nginx -f
Untagged: nginx:latest
Untagged: nginx@sha256:dbe677093f569cc0afe2a149c529645f255aac959490ef11fb19ac6418b815d3
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.100.201:8082/nginx latest 41b0e86104ba 28 hours ago 142MB
sonatype/nexus3 latest be6da324b885 2 weeks ago 691MB
[root@localhost /]# docker rmi 41b0e86104ba -f
Untagged: 192.168.100.201:8082/nginx:latest
Untagged: 192.168.100.201:8082/nginx@sha256:33cef86aae4e8487ff23a6ca16012fac28ff9e7a5e9759d291a7da06e36ac958
Deleted: sha256:41b0e86104ba681811bf60b4d6970ed24dd59e282b36c352b8a55823bbb5e14a
Deleted: sha256:5b8db2b837c760a16b7601957d396e54cb3f380afebdbbe470c196b893595c13
Deleted: sha256:16853b6287c4a49ee01cdb339551006a7f0d44998e3f34d96d278c9bb1231a3b
Deleted: sha256:f7fda29b37af8235a59ddb4605022f5dd11159e691416e107bafce7d1ba9ad8e
Deleted: sha256:7bf023646dc1734fedf0cb2d126ba2012ded08d54f3bc2e53eea922a464632f2
Deleted: sha256:8330aef2496d3fdb47b47c02b9041f29fe572eacb11a028e20c3542242200429
Deleted: sha256:43b3c4e3001c662d1c264ffb132f4e52950893452b15508df810214f1d3f124b
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sonatype/nexus3 latest be6da324b885 2 weeks ago 691MB
[root@localhost /]#
进入网页Nexus仓库

查看nginx镜像成功
镜像pull下载成功:
[root@localhost /]# docker pull 192.168.100.201:8082/nginx:latest
latest: Pulling from nginx
461246efe0a7: Pull complete
a96aaf9a9ec3: Pull complete
650d8b758441: Pull complete
b138da793ac8: Pull complete
bb1705539683: Pull complete
b9ed43dcc388: Pull complete
Digest: sha256:33cef86aae4e8487ff23a6ca16012fac28ff9e7a5e9759d291a7da06e36ac958
Status: Downloaded newer image for 192.168.100.201:8082/nginx:latest
192.168.100.201:8082/nginx:latest
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.100.201:8082/nginx latest 41b0e86104ba 29 hours ago 142MB
sonatype/nexus3 latest be6da324b885 2 weeks ago 691MB