Introduction
Sonatype Nexus 3 is an open source repository manager used to store and manage software artifacts. It provides a central location to store and manage software components and their dependencies, making it easier to manage and distribute software packages within an organization.
Prerequisites
- Minimum 2 core CPU and 4 GB memory required.
- Basic knowledge of Docker.
- Basic knowledge of Linux commands.
- Up and running Docker.
To install Docker and docker compose on ubuntu 22.04 LTS, We can use the given link.
In this post, We will deploy Sonatype Nexus Repository container using Docker Compose on Ubuntu 22.04 LTS machine.
Step 1: Creating docker-compose.yml
To deploy Nexus 3 using Docker Compose, you can create a docker-compose.yml
file with the necessary configurations. Nexus 3 is a repository manager used for managing binary artifacts, and using Docker Compose makes it easier to define and manage the required services.
To create a docker-compose.yml
sudo nano docker-compose.yml
Copy and paste the followings configuration.
version: '3'
services:
nexus:
image: sonatype/nexus3
container_name: nexus
ports:
- "8081:8081"
volumes:
- ./nexus-data:/nexus-data
environment:
- INSTALL4J_ADD_VM_PARAMS=-Xms2g -Xmx2g
networks:
default:
external:
name: some-existing-network
In this example:
sonatype/nexus3
is the official Nexus 3 Docker image.- We expose port
8081
, which is the default port Nexus 3 uses. - A volume is mounted to persist Nexus data.
Save and exit from the text editor.
Step 2: Deploy MongoDB Container
To deploy this nexus service, follow these steps, Run the following command to start the nexus container:
sudo docker-compose up -d
The -d flag runs the containers in the background, It will take few sec or mins to pull the image and deploy the nexus.
Step 3: Validate the Container
To check the running containers launched by Docker Compose, you can use the following command:
sudo docker-compose ps
This command provides a summary of the status of each service defined in your docker-compose.yml file. It shows information such as the service name, container ID, status, ports, and names.
Here’s an example of what the output might look like:
Name Command State Ports
-------------------------------------------------------------------------
nexus docker-entrypoint.sh nexus Up 0.0.0.0:8081->8081/tcp
Step 4: Logging
Some time we need to also check the real time logs, So we can use the given commands.
sudo docker-compose logs -f nexus
Step 5: Destroy Nexus Container
To destroy (stop and remove) the MangoDB container launched with Docker Compose, you can use the following command in the directory where your docker-compose.yml
file is located:
sudo docker-compose down
This command stops and removes all the containers, networks, and volumes defined in your docker-compose.yml
file.
The down command stops and removes the containers but retains the data volumes by default. If you want to remove the volumes as well, you can use the -v
option:
sudo docker-compose down -v
Make sure you are in the correct directory containing your docker-compose.yml
file when running these commands. This ensures that Docker Compose identifies the correct configuration file.
After running the docker-compose down command, you can use the docker-compose ps
command to verify that the containers are no longer running. The output should be empty, indicating that no containers are currently running.
Remember that this command will stop and remove all the services defined in your docker-compose.yml
file, not just the nexus service. If you only want to remove a specific service, you can specify the service name:
docker-compose down -v <service_name>
Replace <service_name>
with the actual name of the service you want to remove.
Conclusion
We have successfully deployed Sonatype Nexus Repository container using Docker Compose on Ubuntu 22.04 LTS machine, If you still have questions, please post them in the comments section below.