5. Retrieve the Admin Password
Nexus generates an admin password on first startup. Retrieve it using:
docker exec -it nexus cat /nexus-data/admin.password
Use this password to log in with the username admin.
6. Change the Admin Password
Upon first login, you’ll be prompted to change the default password. Choose a strong password for security.
7. Configure a Repository (Example: Maven)
- Navigate to Repositories in the Nexus UI.
- Click Create Repository.
- Choose Maven (hosted).
- Set Repository Name (e.g.,
maven-releases). - Click Create Repository.
Repeat for other repository types as needed (Docker, NPM, etc.).
Example: Pushing an Artifact to Nexus
Here’s how to upload a Maven package to your Nexus repository:
1. Configure settings.xml
Add the Nexus repository details in your Maven settings.xml file:
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>your-password</password>
</server>
</servers>
2. Deploy an Artifact
Use Maven to deploy an artifact:
mvn deploy -DrepositoryId=nexus -Durl=http://localhost:8081/repository/maven-releases/
Stopping & Removing Nexus Container
If you need to stop or remove the Nexus container:
docker stop nexus && docker rm nexus
To remove the image completely:
docker rmi sonatype/nexus3
Conclusion
Setting up a local Nexus artifact repository using Docker is a simple and efficient way to manage dependencies and artifacts for development and DevOps workflows. It enhances performance, security, and control over software artifacts. Start using Nexus today to optimize your build and deployment processes!