Self-managed GitLab의 Container Registry 정리 방법

2022. 8. 11. 02:05서버 프로그래밍

도커라이징된 백엔드/프론트엔드 Docker 이미지를 Container Registry를 이용하여 Deploy 하도록 시스템을 구성해놓았는데, GitLab이 설치된 EC2 인스턴스의 용량이 계속 늘어나는 문제가 발생하였다. Settings/Pakages & Registries에서 클린업을 활성화하면 될것 같았는데, 뭔가 원하는대로 되지 않는다.

그래서 좀더 찾아보니, "Garbage Collect"가 존재한단다. 헐

Garbage Collection

Running Garbage Collection will delete all image layers which aren’t linked to a tag. This will result in the removal of images that got untagged by your cleanup policy. It can also dispose of old layers which became redundant when you pushed a new version of a tag.

Garbage Collection must be invoked manually via GitLab’s command line interface. Connect to your GitLab server over SSH and run the following command:

sudo gitlab-ctl registry-garbage-collect
 

The Garbage Collection process will run. Any unused tags within your Container Registry will be recycled. Garbage Collection looks for untagged images across your entire GitLab instance.

Assuming you let the cleanup policy run first, you should now see a healthy reduction in storage use. If it’s your first time running garbage collection on a frequently used GitLab installation, you might have reclaimed several gigabytes of space.

Removing Untagged Manifests and Layers

You can reclaim even more space by instructing garbage collection to also remove untagged image manifests and unreferenced layers. This is a more destructive operation, although it’s normally what you’re expecting to see.

sudo gitlab-ctl registry-garbage-collect -m

Adding the -m flag will delete any layer not directly associated with a tagged image manifest. This results in the loss of cached layers and intermediate build steps.

 

위의 명령을 콘솔에서 실행하니 바로 불필요한 이미지들이 삭제되어서 충분한 디스크 공간이 확보되었다.

속이 다 시원하네.

설마 이 명령을 주기적으로 실행되도록 만들어야 하는건가... 헐

https://www.howtogeek.com/devops/how-to-garbage-collect-the-gitlab-container-registry-to-free-up-storage/

 

How to Garbage Collect the GitLab Container Registry to Free Up Storage

GitLab’s Container Registry provides a convenient place to store your Docker images. Over time, the Container Registry can eat up your disk space as more layers are added. Here’s how to free up storage by removing redundant material.

www.howtogeek.com