- log in to DTR from local client
docker login <dtr-url>
- (optional) create a volume to hold our old images
docker volume create registry
cp -r /path/to/registry/backup/_data /var/lib/docker/volumes/registry/.
- stand up a docker/registry:v2 locally:
# using docker volume
docker run -v registry:/var/lib/registry -d -p 5000:5000 --name registry registry:2
# mounting the registry data directly from filesystem
docker run -v /path/to/registry/backup:/var/lib/registry -d -p 5000:5000 --name registry registry:2
- curl the registry and check for repos and tags:
for repo in $(curl -SsL http://localhost:5000/v2/_catalog | jq -r '.repositories[]')
do
curl -SsL http://localhost:5000/v2/$repo/tags/list
done | jq '.'
- iterate over the repositories dir in the filesystem and create repos:
# 1) navigate to root of repositories folder
# if using docker volume
cd /var/lib/docker/volumes/registry/_data/docker/registry/v2/repositories
# if using filesystem path
cd /path/to/registry/volume/_data/docker/registry/v2/repositories
# 2) grind on the namespace/repo combinations:
#!/bin/bash
DTR_URL="dtr.local.antiskub.net"
ADMIN="admin"
PASSWORD="orca1234"
BEARER_TOKEN=$(curl -kLsS -u $ADMIN:$PASSWORD "https://$DTR_URL/auth/token" | jq -r '.token')
CURLOPTS=(-kLsS -H 'accept: application/json' -H 'content-type: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}")
for NS in $( find * -maxdepth 0 -type d ); do
cd $NS
for REPO in $( find * -maxdepth 0 -type d ); do
curl "${CURLOPTS[@]}" -X POST -d \
"{\
\"name\": \"$REPO\",\
\"shortDescription\": \"$REPO\",\
\"longDescription\": \"$REPO\",\
\"visibility\": \"public\",\
\"scanOnPush\": false,\
\"immutableTags\": false,\
\"enableManifestLists\": true\
}" "https://${DTR_URL}/api/v0/repositories/$NS"
done
cd ..
done
- next, pull list of repos/tags from old registry, tag them, and push them into DTR
for repo in $(curl -SsL http://localhost:5000/v2/_catalog | jq -r '.repositories[]')
do
curl -SsL http://localhost:5000/v2/$repo/tags/list; done | jq -r '. | { name: .name, tags: .tags[] } | "\(.name, .tags)"' | while read -r repo
do
read -r tag
echo "pulling ${repo}:${tag} from OSS registry"
docker pull "localhost:5000/${repo}:${tag}"
echo "tagging ${repo}:${tag} as ${DTR_URL}/${repo}:${tag}"
docker tag "localhost:5000/${repo}:${tag}" "${DTR_URL}/${repo}:${tag}"
echo "pushing ${DTR_URL}/${repo}:${tag}"
docker push "${DTR_URL}/${repo}:${tag}"
echo "delete localhost:5000/${repo}:${tag} from local cache"
docker rmi "localhost:5000/${repo}:${tag}"
done
done