我如何创build一个默认的用户名和密码的sonatype / nexus的docker集装箱?

我的docker写作是简单的:

version: "3" services: nexus: container_name: nexus image: sonatype/nexus:2.14.5-02 ports: - "8081:8081" ... (some other services) 

现在,我必须启动它,然后以pipe理员身份login以创build公司用户。 我可以通过将自定义configuration作为卷来添加自定义用户吗? 如果是这样,那是什么configuration? 还是有另一种方法来做到这一点。

请注意,我也尝试创build容器,添加用户,创build一个图像。 这没有奏效,用户在重启时消失了。

您需要创build两个xml文件security-configuration.xml和security.xml文件。 在security.xml文件中,您可以添加所有必需的用户。 您可以检查security.xml的链接。 Security.xml细节

用这两个文件创build一个文件夹,并用作该文件夹的卷。 在/ opt / nexus / nexus-data / conf文件夹中的容器内使用该卷。

通过一些更多的实验find解决scheme。 在启动sonatype / nexus docker镜像时创build一个自定义用户:

  1. 手动启动一个sonatype / nexus,在pipe理员的浏览器login,创build自定义用户,并至less分配一个angular色。
  2. ${SONATYPE_WORK}/conf/security.xml保存到本地磁盘。 这是必要的,因为密码需要被编码。 解密密钥在同一图像的容器之间不会改变。
  3. docker-compose.yaml的命令创build一个封装shell脚本。 这将包含至less三个步骤:

    A.运行nexus应用程序作为后台进程(我从父Dockerfile的CMD中复制并添加到它) ${JAVA_HOME}/bin/java \ -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH} \ -Xms${MIN_HEAP} -Xmx${MAX_HEAP} \ -cp 'conf/:lib/*' \ ${JAVA_OPTS} \ org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF} &

    B.在nexus应用程序启动后(为简单起见,我在这里添加了5秒的睡眠时间)将保存的security.xml复制到${SONATYPE_WORK}/conf/security.xml 。 这应该已经在docker-compose.yaml中加载到ANYWHERE BUT $ {SONATYPE_WORK} / conf中 ,这会在启动时崩溃nexus应用程序(我只能推测为什么…)

    C.执行任何永久命令,以便容器不会退出。 一个想法是将nexus应用程序重新连接到shell。 还有一个tail -f /path/to/something.txt可以工作。

现在,您应该可以运行docker-compose并使用浏览器上的自定义用户login。

这里供参考我的文件:

init.sh(这是命令包装)

 #!/usr/bin/env bash set -x ${JAVA_HOME}/bin/java \ -Dnexus-work=${SONATYPE_WORK} -Dnexus-webapp-context-path=${CONTEXT_PATH} \ -Xms${MIN_HEAP} -Xmx${MAX_HEAP} \ -cp 'conf/:lib/*' \ ${JAVA_OPTS} \ org.sonatype.nexus.bootstrap.Launcher ${LAUNCHER_CONF} & # here some delay may be necessary, or a function to wait the nexus app to populate ${SONATYPE_WORK}/conf. sleep 5 cp /nexus-dependencies/security-test.xml ${SONATYPE_WORK}/conf/security.xml # I'm also copying nexus.xml to customize the Snapshot repository. cp /nexus-dependencies/nexus.xml ${SONATYPE_WORK}/conf/nexus.xml tail -f /nexus-dependencies/init-nexus.sh 

注意: /nexus-dependencies是我在docker-compose.yaml中加载的卷。 该目录包含我的security.xml版本,其中包含两个用户(公司和pipe理员)以及他们的angular色。 如果用户没有任何angular色,则不可用。

security.xml(这是从手动创build的实例中复制的)

 <?xml version="1.0" encoding="UTF-8"?> <security> <version>2.0.5</version> <!-- Users --> <users> <!-- The Company User --> <user> <id>companyX</id> <firstName>First</firstName> <lastName>Last</lastName> <password>$shiro1$SHA-512$SOME-ENCODED-PASSWORd-COPIED-FROM-A-PREVIOWS-INSTANCE-OF-THIS-IMAGE==</password> <!-- <password>RF1Dkings</password> --> <status>active</status> <email>what@not.com</email> </user> <!-- The Admin User --> <user> <id>admin</id> <firstName>Administrator</firstName> <lastName>User</lastName> <password>$shiro1$SHA-512$This could just be the custom admin password, or not.</password> <status>active</status> <email>changeme@yourcompany.com</email> </user> </users> <!-- Roles --> <userRoleMappings> <!-- CompanyX User role mapping --> <userRoleMapping> <userId>companyX</userId> <source>default</source> <roles> <role>nx-developer</role> </roles> </userRoleMapping> <!-- End CompanyX User role mapping --> <!-- Admin User Roles --> <userRoleMapping> <userId>admin</userId> <source>default</source> <roles> <role>nx-admin</role> </roles> </userRoleMapping> <!-- End Admin User Roles --> </userRoleMappings> </security> 

泊坞窗,compose.yaml

 version: "3" services: ... nexus: container_name: nexus image: sonatype/nexus:2.14.5-02 ports: - "8081:8081" volumes: - ./nexus-dependencies:/nexus-dependencies command: bash /nexus-dependencies/init.sh ... 
Interesting Posts