虚拟机地址(安装docker server的机器):192.168.31.109
镜像版本:sonatype/nexus3:3.17.0
1、编辑docker-compose.yml
[root@kafka1 nexus3]# cat docker-compose.yml
version: '3.1'
services:
nexus3:
image: sonatype/nexus3:3.17.0
container_name: nexus3
# network_mode: host
ports:
- 8081:8081
- 8088:8088
- 8087:8087
- 8086:8086
volumes:
- /root/nexus3/nexus-data:/nexus-data
restart: always
cap_add:
- ALL
2、关闭selinux和修改/root/nexus3/nexus-data (备注:我自己的nexus的目录,映射到容器做文件存储,修改为自己的)
- 关闭selinux
不关闭selinux,无法启动,会报没有权限,类似jvm.log无法创建,或者.pid无法创建
将 SELINUX=enforcing 改为 SELINUX=disabled
[root@kafka1 nexus3]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
- 修改权限
chmod -R 777 ./nexus-data
3、启动nexus3
docker-compose -f ./docker-compose.yml up -d
4、访问nexus3
地址:http://ip:8081 如:http://192.168.31.109:8081
点击右上角的sign in进行登录。账户admin,密码:默认密码在文件 /nexus-data/admin.password 中,登录进入
5、创建仓库
docker的仓库类型有三种
- hosted : 本地存储,即同docker官方仓库一样提供本地私服功能
- proxy : 提供代理其他仓库的类型,如docker中央仓库
- group : 组类型,实质作用是组合多个仓库为一个地址
- 创建hosted仓库
- 创建proxy仓库,代理docker hub
- 创建group仓库,聚合hosted和proxy仓库,实现的效果就是先拉本地仓库,在拉远程仓库
6、设置docker从本地拉取镜像
vi /etc/docker/daemon.json
[root@kafka1 nexus3]# cat /etc/docker/daemon.json
{
"insecure-registries": [
"192.168.31.109:8088",
"192.168.31.109:8087",
"192.168.31.109:8086"
]
}
使用docker info查看
7、打tag进行镜像上传
注:只有hosted的仓库才能上传
将本地从docker hub拉取的mysql镜像,重启打tag 格式ip:hosted port/xxx
docker tag mysql:8.0.16 192.168.31.109:8088/mysql:8.0.16
docker login 192.168.31.109:8088
#输入账户、密码,如使用admin的账户,admin/admin123(第一次登陆后修改为了此密码)
8、上传镜像
docker push 192.168.31.109:8088/mysql:8.0.16
9、查看nexus3的镜像,如下图
10、删除本地镜像重新从私服拉取镜像
docker image rmi 192.168.31.109:8088/mysql:8.0.16
11、删除本地镜像
12、未解决的问题
由于本地仓库只有hosted的keypush镜像,端口为8088,聚合仓库可以先拉取本地仓库,在本地仓库没有的情况去远程仓库拉取,端口为8086
所以在push/pull需要区分端口进行操作,略显麻烦,可以使用nginx进行反向代理进行统一,待完善