Docker deploys Nexus Maven private library
Environment:
Operating system: Linux Centos8
docker version: 20.10.23
docker image:
REPOSITORY TAG IMAGE ID CREATED SIZE sonatype/nexus3 latest 589f7296a4a2 22 months ago 655MB
Nexus official website: https://www.sonatype.com/nexus-repository-oss
Effect
Steps
1. Pull the image
Command:
docker pull docker.io/sonatype/nexus3
Output:
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
Check the image to make sure the image is successfully pulled:
# View image command docker images # Output results REPOSITORY TAG IMAGE ID CREATED SIZE sonatype/nexus3 latest 589f7296a4a2 22 months ago 655MB ...
2. Create a hanging directory
# Create a hanging directory mkdir -p /SystemUtils/Data/Nexus3/nexus-data # Set permissions for the newly created directory so that the docker container has permission to access it. sudo chmod 777 /SystemUtils/Data/Nexus3/nexus-data
3. Run the container
Run the container:
docker run -id --name nexus \ -p 8000:8081 \ -e NEXUS_CONTEXT=nexus \ -v /SystemUtils/Data/Nexus3/nexus-data:/nexus-data \ docker.io/sonatype/nexus3
Command analysis:
Command | Description |
---|---|
docker run | Container run command |
-id | Indicates running in the background |
–name nexus | Specify the container name, here The name is nexus |
-p 8000:8081 | The host port and the container port are mapped, here The host port is 8000 and the container port is 8081 |
-e NEXUS_CONTEXT=nexus | is an environment variable, Usually used to set the Nexus context path when starting the Nexus service. This environment variable can be used to specify the root path of the Nexus service when it is running, such as http://localhost:8081/nexus. |
-v /SystemUtils/Data/Nexus3/nexus-data:/nexus-data | Change the container The directory is hung on the host machine |
docker.io/sonatype/nexus3 | Mirror name, indicating the running Which image is it? |
Check whether the container runs successfully: |
# View currently running containers docker ps # Output results 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
If the query is not found here, the operation failed.
At this time, check the log analysis error command: docker logs -f [container id/container name]
docker logs -f 92d88dd2a1dd
Then analyze the problem and solve it based on the log results.
I encountered the following error here
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
Encountering this error means that the created container cannot write data to the hanging directory, so the authorization step in the second step is indispensable.
4. Access the warehouse console
Access address: http://IP of your deployment:Port of your deployment/nexus
What I deploy here is: http://192.168.2.190:8000/nexus
Enter the address into the browser address bar and press Enter to enter, as shown below
Click Sign in
in the upper right corner to log in
The default user is: admin
The initial password needs to be checked inside the container, as follows:
Enter the container command: docker exec -it [container name/container id] /bin/bash
docker exec -it 92d88dd2a1dd /bin/bash
Enter the password storage directory
# Enter directory cd /nexus-data/ # View directory contents ls -l # Output results 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
View password
cat admin.password # or viadmin.password # Remember to exit when using vi
It is over now. After obtaining the password, log in with the user name. After logging in, you will be prompted to update the password. Just follow the prompts to perform the grouping.