Back to articles
DevOps & Systems

Optimizing Container Management: Building a Private Docker Registry with Harbor and Cosign

A detailed guide on building a Private Docker Registry using Harbor and Cosign to ensure security, control, and optimized container management in DevOps environments.

DPTCloud Engineering4 min read
Optimizing Container Management: Building a Private Docker Registry with Harbor and Cosign

In modern software development, effective and secure container management is a critical factor in ensuring system stability and security. With the rapid growth of Docker and containerization technologies, building a Private Docker Registry not only allows organizations to manage internal container images but also enhances security and optimizes CI/CD workflows. In this guide, we will explore how to build a Private Docker Registry using Harbor and Cosign to ensure safety, version control, and optimized container management in DevOps environments.

Why Build a Private Docker Registry?

A Private Docker Registry is an internal service for storing Docker images, enabling organizations to manage and share container images without relying on public registries like Docker Hub. Using a Private Registry offers several benefits:

  • Higher security: Container images can be controlled and access permissions managed, reducing the risk of exposing sensitive information.
  • Version control: Easily manage and track image versions, especially useful in development and production environments.
  • Better performance: Accessing images from an internal registry is typically faster than downloading from public registries, particularly when internet connectivity is slow or restricted.
  • Storage optimization: Control storage usage and remove unnecessary images.

Building a Private Docker Registry with Harbor

Harbor is a powerful open-source solution for building Private Docker Registries. It provides features such as user authentication, role-based access control, image scanning, and integration with popular DevOps tools.

Requirements and Preparation

  • Server or VPS with Linux OS (Ubuntu 20.04/22.04 or CentOS 7/8)
  • At least 2GB RAM and 10GB disk space
  • Docker and Docker Compose installed
  • Static domain name or IP address for the server

Installing Harbor

We will use Docker Compose to deploy Harbor. First, download the docker-compose.yml file from the official Harbor repository:

curl -L https://github.com/goharbor/harbor/releases/download/v2.7.0/harbor.yml -o harbor.yml

Then, edit the harbor.yml file to match your environment. For example:

hostname: registry.example.com
https:
  port: 443
  certificate: /your/certificate/path
  private_key: /your/private/key/path
harbor_admin_password: your_secure_password

Run the following command to start Harbor:

docker-compose up -d

After completion, access https://registry.example.com to log in and manage container images.

Image Signing and Verification with Cosign

Cosign is an open-source tool that allows signing and verifying Docker images, ensuring that images have not been tampered with or forged. Integrating Cosign with Harbor enhances security and quality control of images.

Installing Cosign

To install Cosign, you can use a package manager or download it from GitHub:

curl -sSL https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 -o cosign
chmod +x cosign
sudo mv cosign /usr/local/bin/

Signing Images

To sign a Docker image, first generate a public-private key pair:

cosign generate-key-pair

Then, sign the image:

cosign sign registry.example.com/my-image:latest

To verify an image, use the following command:

cosign verify registry.example.com/my-image:latest

Preparation and Testing

Before deploying to production, ensure that:

  • Harbor and Cosign are correctly installed.
  • Images are signed and verified successfully.
  • CI/CD pipelines are updated to use the Private Registry and Cosign.

Troubleshooting

If you encounter issues during Harbor deployment, check the following:

  • Ensure Docker and Docker Compose are installed.
  • Verify that the harbor.yml file is correctly configured.
  • Check Harbor logs using the command: docker-compose logs -f.

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478