As businesses increasingly rely on containerization technologies, the need for a reliable and secure Docker image registry becomes paramount. Harbor, an open-source project, provides a robust solution for storing and distributing container images in cloud-native environments. In this comprehensive guide, we will walk you through the step-by-step process of installing Harbor Docker Image Registry on an Ubuntu 22.04 server. By the end of this tutorial, you will have a fully functional Harbor installation, allowing you to securely manage your container artifacts.
Prerequisites
Before we dive into the installation process, let’s ensure that we have all the necessary prerequisites in place:
- An Ubuntu 22.04 server: We will be using a generic and fresh Ubuntu server with the hostname ‘harbor-server.’
- A non-root user with root/administrator privileges: This user will be used to perform administrative tasks during the installation.
- A domain name or local domain: This will be used to access the Harbor installation.
Installing Docker CE (Community Edition)
To deploy Harbor via Docker, we first need to install Docker CE (Community Edition) on our Ubuntu server. Docker CE offers a range of installation options, and in this guide, we will install it from the official Docker repository. Let’s start by installing some basic dependencies using the apt command:
sudo apt install ca-certificates curl gnupg sb-release
Once the dependencies are installed, we need to download the GPG key for the Docker repository and add the official Docker repository to our system. Run the following commands:
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Next, refresh and update the package index using the apt command:
sudo apt update
With the Docker repository added, we can now proceed to install Docker CE and Docker Compose using the following command:
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
After the installation is complete, verify the current status of the Docker service using the systemctl command:
sudo systemctl is-enabled docker
sudo systemctl status docker
Downloading Harbor Installer and Configuring Installation
Now that Docker is installed, we can move on to downloading the Harbor installer package and configuring the installation. Harbor offers both offline and online installers, and for this guide, we will use the offline installer. Let’s download the offline installer to the ‘/tmp’ directory using the curl command:
cd /tmp curl -s https://api.github.com/repos/goharbor/harbor/releases/latest | grep browser_download_url | cut -d '"' -f4 | grep'.tgz
Once the download is complete, extract the installer package using the tar command:
tar -xzvf harbor-offline-installer-v2.6.1.tgz
Now, move the ‘harbor’ directory to ‘/opt’ to set the installation directory as ‘/opt/harbor’:
sudo mv harbor /opt/
With the Harbor installer package downloaded and extracted, we can now proceed to configure the installation. Navigate to the Harbor installation directory:
cd /opt/harbor
Copy the harbor configuration template ‘harbor.yml.tmpl’ to ‘harbor.yml’ using the cp command:
cp harbor.yml.tmpl harbor.yml
Open the ‘harbor.yml’ file using a text editor such as nano:
sudo nano harbor.yml
In the configuration file, you will set up the domain name for the Harbor installation, enable secure HTTPS, set up an admin password, and configure the database. Make the following changes in the file:
- Set the hostname to your desired domain name or IP address. For example,
registry.shapehost.io. - Uncomment the ‘https’ section and provide the path to your SSL certificate and private key files.
- Set the ‘harboradminpassword’ to a strong password of your choice.
- Configure the database section as per your requirements.
Save the file and exit the editor. Your Harbor installation is now configured and ready for deployment.
Installing Harbor via Installer Script and Docker Compose
With the Harbor offline installer downloaded and the configuration file set up, we can now proceed to install Harbor using the installer script and Docker Compose. Before starting the installation, ensure that your current working directory is ‘/opt/harbor’. To install Harbor, run the following command with sudo privileges:
sudo./install.sh
The installer script will perform a series of checks to ensure that the system meets the requirements for Harbor installation. It will verify the presence of Docker engine and Docker Compose. If any dependencies are missing, the installer will prompt you to install them.
Once the prerequisites are met, the installer will proceed to extract the necessary images for Harbor deployment. Afterward, it will prepare the system environment and generate the required configurations. Finally, the installation process will begin.
Once the installation is complete, you should see the output indicating that the Harbor container services are running. To verify the status of the container services, use the following command:
docker compose ps
This command will display the running and healthy Harbor container services.
Accessing Harbor Image Registry and Basic Administration
Now that Harbor is installed, let’s verify its functionality by accessing the Harbor image registry and performing basic administrative tasks.
To access the Harbor web interface, open your web browser and visit the domain name or IP address associated with your Harbor installation, using HTTPS. For example, https://registry.shapehost.io/. You should see the Harbor login page.
To log in, use the default admin user and the password you configured in the ‘harbor.yml’ file. Once logged in, you will be greeted with the Harbor dashboard, where you can manage your projects and repositories.
To create a new user, navigate to the ‘Administration’ section, click on ‘Users,’ and then click the ‘NEW USER’ button. Fill in the details for the new user and save the changes. The new user will now be able to log in to Harbor using their credentials.
Harbor organizes container images into projects. By default, it provides a project named ‘library.’ To add a user to a project, go to the ‘Project’ menu and click on the desired project, such as ‘library.’ From there, click on ‘Members’ and then the ‘USER’ button to add a user to the project. Assign the appropriate role to the user, such as ‘Project Admin,’ and save the changes.
Logging in to Harbor via Docker Client and Pushing Images
To interact with Harbor using the Docker command-line interface (CLI), you need to log in to Harbor from your terminal. Ensure that Docker is installed on your local machine and run the following command:
docker login https://registry.shapehost.io/
Enter the username and password for the user you created in the previous step. Once authenticated, you can now pull and push images to the Harbor image registry.
To push an image to Harbor, first, pull an image from a public repository using the Docker CLI. For example, let’s pull the latest version of the ‘nginx’ image with the ‘alpine’ tag:
docker pull nginx:alpine
Verify that the image is successfully downloaded by running:
docker images
Next, tag the image with the Harbor registry address and project name. For example:
docker tag nginx:alpine registry.shapehost.io/library/nginx:alpine
Finally, push the image to the Harbor registry using the following command:
docker push registry.shapehost.io/library/nginx:alpine
The image will now be uploaded to the Harbor image registry and associated with the specified project.
Conclusion
Congratulations! You have successfully installed the Harbor Docker Image Registry on your Ubuntu 22.04 server. With Harbor, you can securely store and distribute container images in your cloud-native environment. By following this guide, you have learned how to configure Harbor, create users and projects, login to Harbor via the Docker CLI, and push images to the registry.
As you continue to explore Harbor, make sure to familiarize yourself with its advanced features such as security policies, role-based access control, vulnerability scanning, and image signing. These features will further enhance the security and reliability of your container image management.
For reliable and scalable cloud hosting solutions, consider Shape.host’s Linux SSD VPS services. Shape.host provides industry-leading cloud infrastructure, ensuring your applications and data are hosted with high-performance and security. Visit Shape.host for more information and start leveraging the power of the cloud for your business.