
Pull and push docker images from Harbor
This tutorial is if you're pulling and pushing back those docker images to Harbor.
Published Feb 10, 2025
We will pull all images from the current Harbor instance before destroying it.
Since you don’t have
.netrc
, we need to configure it for authentication.Create the
.netrc
file:nano ~/.netrc
Add the following lines (replace with actual values):
Save and exit (Ctrl + X, then Y, then Enter).
Set correct permissions :
chmod 600 ~/.netrc
Now, the script can authenticate with Harbor API.
.netrc
should be created on the machine where you will run the backup and restore scripts.- After deploying the new Harbor, make sure the Harbor URL remains the same, or update the image push script.
- Once you create the
.netrc
file, it will be automatically used bycurl
for authentication. You don’t need to "run" it manually.
However, to verify that it is working, you can test it using curl:
curl -n "https://<harbor-url>/api/v2.0/projects"
Run the script to get all image repositories and tags:
./that_script.sh > docker_images
#if permission errror
chmod +x that_script.sh
This will save all image URLs into
docker_images
.GOT THESE ERROR?
- Cannot connect to the Docker daemon at unix:///Users/xxx/.docker/run/docker.sock. Is the docker daemon running → Put the docker software on.
- Error response from daemon: unauthorized: unauthorized to access repository: xxx/xxx/chinstrap, action: pull → docker login <your-harbor-url>
- Check Harbor Permissions in the repo that pull is allowed.
Run the following command to pull each image to your local Docker:
for r in $(cat docker_images) ; do docker pull $r ; done
This ensures that all images are stored locally before we proceed.
You mentioned that Terraform is ready.
Once all images are backed up, you can destroy the old Harbor:
#try remove harbor code and apply change. ONLY IF CONFIDENT.
terraform state list | grep harbor
terraform destroy -target=helm_release.harbor -auto-approve
terraform destroy -target=helm_release.harbor_postgresql_ha -auto-approve
terraform destroy -target=helm_release.harbor_redis -auto-approve
#Then Terraform is managing the namespace, and you can delete it with:
terraform destroy -target=kubernetes_namespace.harbor -auto-approv
To deploy the Docker images back to the new Harbor, follow these steps:
Before pushing images, ensure the new Harbor instance is up and running:
#without HHTPS
curl -u <username>:<password> "https://<new-harborurl>/api/v2.0/projects"
If this returns a list of projects, your new Harbor is ready.
Log in to the new Harbor registry:
docker login <new-harbor-url>
Enter your username and password when prompted.
Since the Harbor URL has changed, you need to retag each image before pushing:
Once tagged, push all images:
Check if images were successfully pushed via the UI or use the API:
- you can also check in the harbor console.
- if project error you might needs to create a project in the Harbor console.
curl -u <username>:<password> "https://<new-harborurl>/api/v2.0/projects"