Docker部署Nexus Maven私库
环境:
操作系统:Linux Centos8
docker 版本:20.10.23
docker 镜像:
REPOSITORY TAG IMAGE ID CREATED SIZE
sonatype/nexus3 latest 589f7296a4a2 22 months ago 655MB
Nexus官网:https://www.sonatype.com/nexus-repository-oss
效果
步骤
1、拉取镜像
命令:
docker pull docker.io/sonatype/nexus3
输出:
Using default tag: latest
latest: Pulling from sonatype/nexus3
26f1167feaf7: Pull complete
adffa6963146: Pull complete
e88dfbe0ef6a: Pull complete
0d43c5e95446: Pull complete
8ff7b45a7e29: Pull complete
Digest: sha256:eff4fb12346ceb5cd424732ee9f2765c0db0f8d5032cdb2f7f7e17acc349f651
Status: Downloaded newer image for sonatype/nexus3:latest
docker.io/sonatype/nexus3:latest
查看镜像,确定镜像拉取成功:
# 查看镜像命令
docker images
# 输出结果
REPOSITORY TAG IMAGE ID CREATED SIZE
sonatype/nexus3 latest 589f7296a4a2 22 months ago 655MB
......
2、创建挂在目录
# 创建挂在目录
mkdir -p /SystemUtils/Data/Nexus3/nexus-data
# 给新建的目录设置权限,以便docker容器有权限访问
sudo chmod 777 /SystemUtils/Data/Nexus3/nexus-data
3、运行容器
运行容器:
docker run -id --name nexus \
-p 8000:8081 \
-e NEXUS_CONTEXT=nexus \
-v /SystemUtils/Data/Nexus3/nexus-data:/nexus-data \
docker.io/sonatype/nexus3
命令分析:
命令 | 说明 |
---|---|
docker run | 容器运行命令 |
-id | 表示后台运行 |
–name nexus | 指定容器名称,这里的名称是nexus |
-p 8000:8081 | 宿主机端口和容器端口进行映射,这里宿主机端口是8000,容器端口是8081 |
-e NEXUS_CONTEXT=nexus | 是一个环境变量,通常用于在启动Nexus服务时设置Nexus的上下文路径(context path)。这个环境变量可以用来指定Nexus服务在运行时的根路径,例如http://localhost:8081/nexus。 |
-v /SystemUtils/Data/Nexus3/nexus-data:/nexus-data | 将容器目录挂在到宿主机 |
docker.io/sonatype/nexus3 | 镜像名称,表示运行的是哪个镜像 |
查看容器是否运行成功: |
# 查看当前运行的容器
docker ps
# 输出结果
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
92d88dd2a1dd sonatype/nexus3 "sh -c ${SONATYPE_DI…" 2 hours ago Up 2 hours 0.0.0.0:8000->8081/tcp, :::8000->8081/tcp
如果在这里未查询到说明运行失败
这时查看日志分析错误 命令:docker logs -f [容器id/容器名]
docker logs -f 92d88dd2a1dd
然后根据日志结果去分析问题进行解决
我这里遇到了如下的错误
mkdir: cannot create directory '../sonatype-work/nexus3/log': Permission denied
mkdir: cannot create directory '../sonatype-work/nexus3/tmp': Permission denied
OpenJDK 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to No such file or directory
Warning: Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning: Forcing option -XX:LogFile=/tmp/jvm.log
java.io.FileNotFoundException: ../sonatype-work/nexus3/tmp/i4j_ZTDnGON8hezynsMX2ZCYAVDtQog=.lock (No such file or directory)
at java.io.RandomAccessFile.open0(Native Method)
at java.io.RandomAccessFile.open(RandomAccessFile.java:316)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:243)
at com.install4j.runtime.launcher.util.SingleInstance.check(SingleInstance.java:72)
at com.install4j.runtime.launcher.util.SingleInstance.checkForCurrentLauncher(SingleInstance.java:31)
at com.install4j.runtime.launcher.UnixLauncher.checkSingleInstance(UnixLauncher.java:88)
at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:67)
java.io.FileNotFoundException: /nexus-data/karaf.pid (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:101)
at org.apache.karaf.main.InstanceHelper.writePid(InstanceHelper.java:126)
at org.apache.karaf.main.Main.launch(Main.java:271)
at org.sonatype.nexus.karaf.NexusMain.launch(NexusMain.java:113)
at org.sonatype.nexus.karaf.NexusMain.main(NexusMain.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85)
at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:69)
java.lang.RuntimeException: /nexus-data/log/karaf.log (No such file or directory)
at org.apache.karaf.main.util.BootstrapLogManager.getDefaultHandlerInternal(BootstrapLogManager.java:102)
at org.apache.karaf.main.util.BootstrapLogManager.getDefaultHandlersInternal(BootstrapLogManager.java:137)
at org.apache.karaf.main.util.BootstrapLogManager.getDefaultHandlers(BootstrapLogManager.java:70)
at org.apache.karaf.main.util.BootstrapLogManager.configureLogger(BootstrapLogManager.java:75)
at org.apache.karaf.main.Main.launch(Main.java:272)
at org.sonatype.nexus.karaf.NexusMain.launch(NexusMain.java:113)
at org.sonatype.nexus.karaf.NexusMain.main(NexusMain.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85)
at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:69)
Caused by: java.io.FileNotFoundException: /nexus-data/log/karaf.log (No such file or directory)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at org.apache.karaf.main.util.BootstrapLogManager$SimpleFileHandler.open(BootstrapLogManager.java:193)
at org.apache.karaf.main.util.BootstrapLogManager$SimpleFileHandler.<init>(BootstrapLogManager.java:182)
at org.apache.karaf.main.util.BootstrapLogManager.getDefaultHandlerInternal(BootstrapLogManager.java:100)
... 12 more
Error creating bundle cache.
Unable to update instance pid: Unable to create directory /nexus-data/instances
遇到这个错误说明,创建的容器无法向挂在的目中写入数据,因此第二步中的授权步骤是不能少的。
4、访问仓库控制台
访问地址:http://你部署的IP:你部署的端口/nexus
我这里部署的是:http://192.168.2.190:8000/nexus
将地址输入浏览器地址栏然后回车就行进入,如下图
点击右上角的 Sign in
进行登录
默认用户是:admin
初始密码需要去容器内部去查看,如下操作:
进入容器命令:docker exec -it [容器名/容器id] /bin/bash
docker exec -it 92d88dd2a1dd /bin/bash
进入密码存放目录
# 进入目录
cd /nexus-data/
# 查看目录内容
ls -l
# 输出结果
bash-4.4$ ls -l
total 32
-rw-r--r-- 1 nexus nexus 36 Nov 11 14:29 admin.password
drwxr-xr-x 3 nexus nexus 21 Nov 11 14:29 blobs
drwxr-xr-x 336 nexus nexus 8192 Nov 11 14:29 cache
drwxr-xr-x 6 nexus nexus 113 Nov 11 14:29 db
drwxr-xr-x 3 nexus nexus 19 Nov 11 14:29 elasticsearch
drwxr-xr-x 3 nexus nexus 45 Nov 11 14:29 etc
drwxr-xr-x 2 nexus nexus 6 Nov 11 14:29 generated-bundles
drwxr-xr-x 2 nexus nexus 33 Nov 11 14:25 instances
drwxr-xr-x 3 nexus nexus 19 Nov 11 14:25 javaprefs
-rw-r--r-- 1 nexus nexus 1 Nov 11 14:29 karaf.pid
drwxr-xr-x 3 nexus nexus 18 Nov 11 14:29 keystores
-rw-r--r-- 1 nexus nexus 14 Nov 11 14:29 lock
drwxr-xr-x 3 nexus nexus 112 Nov 11 14:29 log
drwxr-xr-x 2 nexus nexus 6 Nov 11 14:29 orient
-rw-r--r-- 1 nexus nexus 5 Nov 11 14:29 port
drwxr-xr-x 2 nexus nexus 6 Nov 11 14:29 restore-from-backup
drwxr-xr-x 7 nexus nexus 4096 Nov 11 14:29 tmp
查看密码
cat admin.password
# 或者
vi admin.password
# 使用vi记得退出
自此已经结束,获取到密码之后配合用户名进行登录,登录之后会提示更新密码,根据提示进行曹组即可。