3

I have a docker local registry:2.6.2, and my Web-UI constantly log an error:

time="2019-08-13T13:58:43Z" level=error msg="Failed to retrieve an updated list of tags for http://172.20.0.20:5000" Error="Get http://172.20.0.20:5000/v2/myrepo/tags/list: http: non-successful response (status=404 body=\"{\\\"errors\\\":[{\\\"code\\\":\\
\"NAME_UNKNOWN\\\",\\\"message\\\":\\\"repository name not known to registry\\\",\\\"detail\\\":{\\\"name\\\":\\\"myrepo\\\"}}]}\\n\")" Repository Name=myrepo file=allregistries.go line=71 source=ap

It happens, becouse of empty repository "myrepo" witch exist om my registry.

curl -X GET http://172.20.0.20:5000/v2/_catalog 
{"repositories":["myrepo","myrepo2","myrepo3"]} 
curl -X GET http://172.20.0.20:5000/v2/myrepo/tags/list 
{"errors":[{"code":"NAME_UNKNOWN","message":"repository name not known to registry","detail":{"name":"myrepo"}}]}

The question is, how to delete this empty repository?

Orest Gulman
  • 422
  • 1
  • 8
  • 25

1 Answers1

1

NOTE: All below example codes are executed with root privilege on ubuntu 20.04 LTS

I use following command to delete emptry repository

docker exec -it registry sh -c '
for t in $(find /var/lib/registry/docker/registry/v2/repositories -name tags)
do
  TAGS=$(ls $t | wc -l)
  REPO=${t%%\/_manifests\/tags}
  LINKS=$(find $REPO/_manifests/revisions -name link | wc -l)
  if [ "$TAGS" -eq 0 -a "$LINKS" -eq 0 ]; then
    echo "REMOVE empty repo: $REPO"
    rm -rf $REPO
  fi
done'
docker restart registry

the registry is the registry that runs on the machine. you can check the name by docker ps

# docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED             STATUS          PORTS                                               NAMES
d3c40930b56b   konradkleine/docker-registry-frontend:v2   "/bin/sh -c $START_S…"   About an hour ago   Up 42 minutes   80/tcp, 0.0.0.0:30443->443/tcp, :::30443->443/tcp   reg-ui
787dd0c13058   registry:2.7.1                             "/entrypoint.sh /etc…"   5 days ago          Up 34 minutes   0.0.0.0:443->443/tcp, :::443->443/tcp, 5000/tcp     registry
#

make sure that both the number of tags and links must be zero. and the docker process must be restarted, if any directories are removed.

If the command works find, you can create a script

cat<<EOM | tee /usr/local/bin/docker-registry-remove-empty-repo.sh
#!/bin/bash

RM_LOG=\$(docker exec -it registry sh -c ' 
for t in \$(find /var/lib/registry/docker/registry/v2/repositories -name tags)
do
  TAGS=\$(ls \$t | wc -l)
  REPO=\${t%%\/_manifests\/tags}
  LINKS=\$(find \$REPO/_manifests/revisions -name link | wc -l)
  if [ "\$TAGS" -eq 0 -a "\$LINKS" -eq 0 ]; then
    echo "REMOVE empty repo: \$REPO"
    rm -rf \$REPO
  fi
done')
if [ -n "\$RM_LOG" ]; then
  echo "\$RM_LOG"
  docker restart registry
fi
EOM
chmod +x /usr/local/bin/docker-registry-remove-empty-repo.sh

even you can run it every minutes by registring the script to the cron

sudo sed -i '/docker-registry-remove-empty-repo.sh/d' /var/spool/cron/crontabs/$USER
cat <<EOM | tee -a /var/spool/cron/crontabs/$USER
* * * * * /usr/local/bin/docker-registry-remove-empty-repo.sh
EOM
systemctl restart cron

after that, all is ok, if you see the following system log

# tail -f /var/log/syslog
Jun  7 02:46:01 localhost CRON[38764]: (root) CMD (/usr/local/bin/docker-registry-remove-empty-repo.sh)
Jun  7 02:46:01 localhost CRON[38763]: (CRON) info (No MTA installed, discarding output)
Jun  7 02:47:01 localhost CRON[38774]: (root) CMD (/usr/local/bin/docker-registry-remove-empty-repo.sh)
Jun  7 02:47:01 localhost CRON[38773]: (CRON) info (No MTA installed, discarding output)
Jun  7 02:48:01 localhost CRON[38795]: (root) CMD (/usr/local/bin/docker-registry-remove-empty-repo.sh)
Jun  7 02:48:01 localhost CRON[38794]: (CRON) info (No MTA installed, discarding output)
Jun  7 02:49:01 localhost CRON[38804]: (root) CMD (/usr/local/bin/docker-registry-remove-empty-repo.sh)
Jun  7 02:49:02 localhost CRON[38803]: (CRON) info (No MTA installed, discarding output)
Jun  7 02:50:01 localhost CRON[38814]: (root) CMD (/usr/local/bin/docker-registry-remove-empty-repo.sh)
Jun  7 02:50:01 localhost CRON[38813]: (CRON) info (No MTA installed, discarding output)



^C
#

Haesung
  • 11
  • 2