Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command for garbage-collect #77

Closed
RANGERBEE opened this issue Apr 15, 2019 · 7 comments · Fixed by #98

Comments

@RANGERBEE
Copy link

commented Apr 15, 2019

Hello,

What is the command for the garbage-collect?

Does it execute on the host?

Thank you!

@Joxit

This comment has been minimized.

Copy link
Owner

commented Apr 15, 2019

Hello,
The command is registry garbage-collect config.yml (It's displayed when you delete an image).

Yes you must execute this on the host (or in the container of your private registry)

@RANGERBEE

This comment has been minimized.

Copy link
Author

commented Apr 15, 2019

I have an idea for an ENV variable on the Registry container.

  • SET ENV Var for Garbage-Collect_CRON=True

This will enable garbage collection ON set to a default of every 24hrs

I would edit the code myself but I just cant find it. ;-)

@Joxit

This comment has been minimized.

Copy link
Owner

commented Apr 15, 2019

Sorry, but the registry image is out of the scope of this project.
The registry image is managed by the docker team here (docker/distribution)

@RANGERBEE

This comment has been minimized.

Copy link
Author

commented Apr 15, 2019

Thank you..

In the interim I am running on HOST:

Dry Run..

sudo docker exec ui-as-proxy_registry_1 registry garbage-collect --dry-run /etc/docker/registry/config.yml

OR - Live..

sudo docker exec ui-as-proxy_registry_1 registry garbage-collect /etc/docker/registry/config.yml

I will try to make an entrypoint file or see if CMD will run properly at end of service config in compose file..

@Joxit Joxit added the wontfix label Apr 16, 2019

@RANGERBEE

This comment has been minimized.

Copy link
Author

commented Apr 16, 2019

@Joxit ,

After a delete and garbage collect the orphaned images are deleted but there is a listing in the Registry-UI that remains. When I click on it it shows no images within.

Is there a way to remove that orphaned listing from the UI as well?

@Joxit

This comment has been minimized.

Copy link
Owner

commented Apr 16, 2019

No, this is a limit from docker registry, see this #53 (comment)
You can delete manually old images by deleting folders.

@RANGERBEE

This comment has been minimized.

Copy link
Author

commented Apr 16, 2019

Here is a snippit of a Bash script I am using for garbage collection and deletion of the orphaned repo..

get_array()
{
	curl --user ${REG_USER} http://${REGISTRY}/v2/_catalog >list
    sed -i -- s#repositories##g list;
    sed -i -- s#\{##g list;
    sed -i -- s#\}##g list;
    sed -i -- s#:##g list;
    sed -i -- s#\\[##g list;
    sed -i -- s#\\]##g list;
    sed -i -- s#\"##g list;
    sed -i -- s#\"##g list;
    sed -i -- s#,#" "#g list;
	ARRAY1=$(cat list)
	garbage_collect
}

garbage_collect()
{
	docker exec ui-as-proxy_registry_1 registry garbage-collect /etc/docker/registry/config.yml	&&
	del_repo 
}

del_repo()
{  
        for i in ${ARRAY1[@]}; do 
    	curl --user ${REG_USER} http://${REGISTRY}/v2/$i/tags/list | grep null ;
      	if [ $? -eq 0 ]; then
        docker exec -it ui-as-proxy_registry_1 rm -rf /var/lib/registry/docker/registry/v2/repositories/$i
    	fi
  	done
}

Note: after deleting an image via the Repository UI the repository remains and is empty - orphaned if you will.. Creating a bash script with the snippit of code to iterate through the tags works to garbage collect and delete the orphaned repository via tags found.

To test properly I needed to restart the registry and UI containers then push the same image back into the registry container - otherwise the layer still exists for the old image somehow and would not allow me to push the image over. After restart of containers i was then able to push my image back into the registry and the UI would show the image once again...

Thank you! I hope this helps others..

//Edited for a fix...

@Joxit Joxit referenced this issue Sep 5, 2019

@Joxit Joxit closed this in #98 Sep 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.