πŸš€ Setting Up a Private Docker Registry in Nexus

πŸš€ Setting Up a Private Docker Registry in Nexus

Β·

3 min read

Managing your own private Docker registry can be a game-changer for secure, fast, and efficient container deployments. In this blog, we’ll guide you through setting up a private Docker registry using Nexus step by step. Follow along to ensure your registry is up and running smoothly! πŸŽ‰


1️⃣ Install Docker 🐳

Before we dive in, ensure Docker is installed on your machine. Follow the instructions for your operating system on the Docker official site.
Verify installation:

sudo apt install docker.io
docker --version

2️⃣ Add Nexus URL to Insecure Registries πŸ”’

If you're hosting Nexus without SSL (not recommended for production):

  1. Locate Docker’s daemon.json file (usually in /etc/docker/daemon.json on Linux or C:\ProgramData\docker\config\daemon.json on Windows).

  2. Add your Nexus server URL under insecure-registries:

     {
       "insecure-registries": ["<your-nexus-url>:<port>"]
     }
    

  3. Restart Docker to apply changes:

     sudo systemctl restart docker  # Linux
    


3️⃣ Set Up Nexus Using a Docker Container πŸ› οΈ

Run Nexus as a Docker container:

docker run -d -p 8081:8081 -p 5000:5000 --name nexus sonatype/nexus3

Access Nexus via your browser at http://<your-server-ip>:8081. Log in using the default credentials:

  • Username: admin

  • Password: Found in the file /nexus-data/admin.password inside the container.


4️⃣ Create a Docker Hosted Repository in Nexus πŸ—οΈ

  1. Navigate to Repositories in the Nexus UI.

  2. Click Create repository β†’ Select Docker (hosted).

  3. Configure the following:

    • Name: docker-private

    • HTTP Port: Specify a port (e.g., 5000).

  4. Save the repository.


5️⃣ Enable Docker Bearer Token Authentication πŸ”‘

  1. Go to Administration β†’ Security β†’ Realms.

  2. Activate Docker Bearer Token Realm by moving it to the active realms list.

  3. Save the settings.


6️⃣ Log In to the Private Docker Registry πŸ“

Authenticate with the private registry:

bashCopy codedocker login <your-nexus-url>:<port>

Provide your Nexus credentials.


7️⃣ Tagging an Image 🏷️

Let’s tag a local Docker image for your private registry:

docker tag <local-image>:<tag> <your-nexus-url>:<port>/<repo-name>/<image_name>:<tag>

For example:

docker tag nginx:latest localhost:5000/docker-private/nginx-latest


8️⃣ Push an Image to the Private Repository πŸ“€

Push the tagged image to your private registry:

docker push <your-nexus-url>:<port>/<repo-name>:<tag>

Example:

docker push localhost:5000/docker-private:nginx-latest


9️⃣ Pull a Public Image, Tag, and Push to Nexus πŸ›³οΈ

  1. Pull a public image from Docker Hub:

     docker pull busybox:latest
    

  2. Tag it for your private registry:

     docker tag busybox:latest localhost:5000/docker-private/busybox:latest
    
  3. Push the tagged image:

     docker push localhost:5000/docker-private/busybox:latest
    


πŸ”Ÿ Remove Local Image and Pull from Private Registry πŸ—‘οΈβ¬‡οΈ

  1. Remove the image from your local machine:

     docker rmi <your-nexus-url>:<port>/<repo-name>:<tag>
    

    Example:

     docker rmi localhost:5000/docker-private:nginx-latest
    
  2. Pull the image from your private registry to verify:

     docker pull <your-nexus-url>:<port>/<repo-name>:<tag>
    

    Example:

     docker pull localhost:5000/docker-private:nginx-latest
    


πŸŽ‰ All Set!

You now have a fully functional private Docker registry hosted on Nexus. You can securely push, pull, and manage Docker images in your repository. πŸ† Happy containerizing! 🚒

Β