Docker部署Nexus Maven私库

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记得退出

自此已经结束,获取到密码之后配合用户名进行登录,登录之后会提示更新密码,根据提示进行曹组即可。

要使用Docker部署Maven项目,您需要首先安装DockerDocker Compose。Docker用于创建、运行和管理容器,而Docker Compose用于定义和运行多个Docker容器。然后,您需要编写Docker Compose文件来描述您的Maven项目以及所需的依赖和服务。 接下来,您可以使用Sonatype Nexus作为Maven私服。通过Docker Compose,您可以轻松地部署和管理Nexus容器。这样,您就可以将您的Maven项目上传到私服中,并通过私服来管理和共享本地的Maven依赖,从而提高开发效率。这样做的好处是,您不需要每次构建项目时都从公共Maven仓库下载依赖,而是可以从本地私服中获取。 总结起来,要使用Docker部署Maven项目,您需要安装DockerDocker Compose,编写Docker Compose文件描述您的Maven项目,并使用Sonatype Nexus作为Maven私服来管理和共享本地的Maven依赖。这样,您可以更方便地构建和部署Maven项目,提高开发效率。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [【Docker】使用 Docker 部署 Maven 仓库](https://blog.csdn.net/m0_47406832/article/details/130597902)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值