Using Harbor as a Self-Hosted Image Registry

  ·   3 min read

In the world of containerization, managing container images efficiently is crucial for seamless deployment and scaling. While Docker Hub is a popular choice for hosting container images, organizations often require a self-hosted solution for better control, security, and compliance. Harbor, an open-source cloud-native registry, is a robust option that provides a secure and scalable environment for managing container images.

In this article, we will explore how to set up Harbor as a self-hosted image registry using Docker Compose, and demonstrate how to upload an image to your Harbor registry.

Prerequisites

Before we begin, ensure you have the following installed on your system:

Step 1: Clone the Harbor Repository

First, clone the Harbor GitHub repository to get the necessary files for deployment.

git clone https://github.com/goharbor/harbor.git
cd harbor

Step 2: Configure Harbor

Navigate to the harbor directory and copy the harbor.yml.tmpl to harbor.yml. This file contains the configuration settings for your Harbor instance.

cp harbor.yml.tmpl harbor.yml

Edit the harbor.yml file to configure your Harbor instance. Key settings include:

  • hostname: Set this to the domain name or IP address of your server.
  • http: Configure the HTTP port if you are not using HTTPS.
  • https: Configure SSL certificates if you are using HTTPS.
  • harbor_admin_password: Set a strong password for the Harbor admin user.

Step 3: Deploy Harbor with Docker Compose

Once your configuration is set, use Docker Compose to deploy Harbor.

./install.sh

This script will use Docker Compose to start all the necessary services for Harbor, including the registry, database, and web portal.

Step 4: Access the Harbor Web Interface

After the installation is complete, you can access the Harbor web interface by navigating to http://<your-hostname> or https://<your-hostname> in your web browser. Log in using the default admin username (admin) and the password you set in the harbor.yml file.

Step 5: Upload an Image to Harbor

To upload an image to your Harbor registry, you need to tag the image with your Harbor registry’s hostname and then push it.

  1. Tag the Image: Suppose you have a local Docker image named myapp:latest. Tag it with your Harbor registry’s hostname.

    docker tag myapp:latest <your-hostname>/library/myapp:latest
    
  2. Log in to Harbor: Use the Docker CLI to log in to your Harbor registry.

    docker login <your-hostname>
    

    Enter your Harbor username and password when prompted.

  3. Push the Image: Push the tagged image to your Harbor registry.

    docker push <your-hostname>/library/myapp:latest
    

Conclusion

Harbor provides a powerful and flexible solution for managing container images in a self-hosted environment. By following the steps outlined in this article, you can set up Harbor using Docker Compose and start managing your container images with ease. Harbor’s rich feature set, including role-based access control, vulnerability scanning, and image replication, makes it an excellent choice for organizations looking to enhance their container management capabilities.

Additional Resources

By leveraging these resources, you can further explore Harbor’s capabilities and customize your deployment to fit your organization’s needs.