Docker registry cannot delete images? - docker

I have deploy a docker registry on my instance, after push images to the registry successfully, I want to perform a delete opearation with curl -XDelete, following the document on docker site, "DELETE /v2/<name>/manifests/<reference>", but the response show not success:
Response:
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>`
Does anyone met such problem?

If there is a redirection and curl is involve, try at least to instruct curl to follow said redirection:
curl -L -XDELETE localhost:5000/v2/hello2/manifests/<Reference>
^^

Related

How to open the internal Docker URL using an external web page?

I'm trying to reproduce the code from this github:enter link description here. The purpose of this project is to use the GPU to perform some similarity search. Based on the instruction of the README file, I can now open the search server website inside the docker now. But I have tried many ways to try to open this server URL from an external browser, but all failed, can anyone help? Thanks!
Here is how I opened my server URL inside the Docker:
Download Docker Desktop.
Pull the images:
docker pull klorton/gpusimilarity:latest
From the docker directory(The docker file is inside the github), build:
docker build -t gpusim:internal .
Build a fingerprint file (Database), change PATH/TO/SMIGZ_DIR to your own path to the smi.gz file, change INPUT to your own smi.gz file.
docker run -v /PATH/TO/SMIGZ_DIR:/data -it gpusim python3 \
/gpusimilarity/bld/python/gpusim_createdb.py /data/INPUT.smi.gz \
/data/OUTPUT.fsim
Start a gpusimilarity server interactively, change /path/to/fsim/files to your own path to the fsim file.
docker run --net=host -v /path/to/fsim/files:/mnt/fsim -it \
klorton/gpusimilarity:latest python3 /gpusimilarity/bld/python/gpusim_server.py \
/mnt/fsim/OUTPUT.fsim --port 8080 --http_interface
The server will say "Ready for search" at this moment. Something like this:
enter image description here
7.The server is running now. In the README file, the author said that we can just use the following link: http://localhost:8080 to open it. But I failed by doing this.
Then I tried to open the URL inside the Docker, install w3m first.
apt-get install -y w3m
Open the URL inside the Docker:
w3m http://localhost:8080
It shows like this:
enter image description here
Can someone tell me how to open this URL outside of Docker? Thanks a lot!
I have tried many of the methods available on Google, But most of them don't work...
I solved this. Just Downgrade docker and run the same process by linux.

How to log in in jfrog container registry?

I start the container registry:
docker run --name artifactory -d -p 8081:8081 -p 8082:8082 docker.bintray.io/jfrog/artifactory-jcr:latest
I was able to login using the UI and create a repository etc.
Now I want to login using the CLI:
docker login localhost:8082
Username: admin
Password:
Error response from daemon: Get http://localhost:8082/v2/: received unexpected HTTP status: 503 Service Unavailable
What am I doing wrong? I got the same error when I use my local 192.168.x.x address (and after adding it to my insecure registries).
I tried it too and had to search for a while.
Using the API I saw: "message" : "status code: 503, reason phrase: In order to use Artifactory you must accept the EULA first"
I didn't find how to sign it using the UI but it worked this way:
$ curl -XPOST -vu admin:password http://localhost:8082/artifactory/ui/jcr/eula/accept
After that I was able to login:
$ curl -XPOST -vu admin:password http://localhost:8082/artifactory/ui/jcr/eula/accept
8:35
docker login localhost:8081/docker/test
Username: admin
Password:
Login Succeeded
First, let us test if the docker client can reach the JCR by running the below curl,
curl -u http://localhost:8082/artifactory/api/docker/docker/v2/token
Moreover, it looks like the docker client isn't taking localhost as the docker container's IP but the server's host, to check this, add the following line in /etc/hosts file,
127.0.0.1 myartifactory
then access it using myartifactory:8082 thru the UI and if it is accessible then use the docker login as "docker login myartifactory:8082"
Because each repo can have different authentication or authorization, you need to login to a specific repo.
Let's say you created a docker repo "myrepo", you can login as follows
docker login localhost:8082/myrepo

remove docker repository on remote docker registry

Given a docker registry managing multiple docker repositories, how do I delete one of the repositores?
Given docker repositories repo1 and repo2.
$ curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo1", "repo2"]}
I want to remove repository repo1 so _catalog does not list repo1, like
$ curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo2"]}
Currently, repository repo1 only has the default "latest" image tag
$ curl -X GET localhost:5000/v2/repo1/tags/list
{"name":"repo1","tags":["latest"]}
(Maybe that affects being able to delete repo1?)
I have tried...
The following commands returned 404 page not found:
$ curl -X DELETE localhost:5000/v1/repositories/repo1
$ curl -X DELETE localhost:5000/v2/repositories/repo1
$ curl -X DELETE localhost:5000/v2/repo1
And the following returned {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
$ curl -X DELETE localhost:5000/v2/repo1/manifests/latest
Using versions
The remote docker-registry is registry/2.0
curl -vX GET localhost:5000/v2/
< HTTP/1.1 200 OK
...
< Docker-Distribution-Api-Version: registry/2.0
...
and
$ /bin/registry github.com/docker/distribution v2.4.1
by enabling DELETE API you're only able to delete the TAG not the whole repository from v2/_catalog.
in order to do this, you should:
1. enable DELETE API:
1.1 by config.yml : storage.delete.enabled:true
1.2 by env: -e REGISTRY_STORAGE_DELETE_ENABLED=true
2. get the tag reference via GET /v2/<name>/manifests/<tag>
(don't forget to have Header Accept: application/vnd.docker.distribution.manifest.v2+json).
in response headers, you have docker-content-digest: <sha256:xxx>
3. send DELETE /v2/<name>/manifests/<sha256:xxx>
4. run garbage collector: bin/registry garbage-collect /etc/docker/registry/config.yml
5. remove files: rm -r /var/lib/registry/docker/registry/v2/repositories/<name>/<tag>
finally: now you can see
curl -X GET localhost:5000/v2/_catalog
{"repositories":["repo2", "repo3"]}
ps.
consequences of 5: https://github.com/docker/distribution/issues/2983#issuecomment-530251232
There is no API to delete a repository. You need to delete individual tags or manifests within the repository. And until OCI's distribution-spec, there wasn't even an API to delete tags, you need to delete image manifests by digest, which deletes all tags pointing to that same digest.
To delete manifests, first ensure that you have enabled deletion according to this documentation before attempting anything. In your configuration of the registry, you would add the following section:
delete:
enabled: true
That can also be set by starting your registry container with the REGISTRY_STORAGE_DELETE_ENABLED=true environment variable specified.
Then you can call the manifest delete API:
curl -X DELETE \
-s "https://registry.example.org/v2/${repo}/manifests/${sha}"
If you want a wrapper around this to handle auth, and even support tag deletion, see regclient's regctl CLI that I've written. Google's crane and RedHat's skopeo may also provide this.
Once the manifests are deleted, you still need to clean the other items the manifest pointed to with a garbage collection (this needs to be done when no writes are occurring):
docker exec registry /bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged
That said, you'll still reach the point where the repository itself is not removed. You can delete the entire directory from the filesystem of the registry. But I would recommend getting support for this implemented from the project. See this issue for more details on getting the capability added to the official registry image.

docker API v2 - how to tag and push an image

I want to promote image from test to prod environment. How do I use "curl POST" to tag and push an image thru docker registry API v2? (Docker API 1.22)
The equivalent command are:
docker tag my_testrepo:6000/new_test_image:test_tag myprod_repo:5000/new_prod_image:tag
docker push myprod_repo:5000/new_prod_image:tag
How do I use curl command to tag an image into a repo:
POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1
Could not find any instructions. Tried many times, all failed.
While researching this issue I stumbled upon this question. The solution I found resolved around this blog post. Credit to wheleph for the solution.
Essentially there is no method to tag an existing image, you can simply download the manifest of the existing tag, and re-upload the manifest as a new tag:
curl /v2/mybusybox/manifests/latest -H 'accept: application/vnd.docker.distribution.manifest.v2+json' > manifest.json
Then upload that manifest file back up.
curl -XPUT '/v2/mybusybox/manifests/new_tag' -H 'content-type: application/vnd.docker.distribution.manifest.v2+json' -d '#manifest.json'

Can't delete Docker Image from Registry

Hi I want to delete a docker image from my private registry the steps that I did was:
I already did what the solution of How can I use the Docker Registry API V2 to delete an image from a private registry? recommended and it did not work
I did a HEAD request to get the Docker-Content-Digest
curl --cacert ~/Documents/certificates//ca.pem --key ~/Documents/certificates//key.pem --cert ~/Documents/certificates/certificate.p12 --pass certpass -I https://myprivateregistry/v2/imagename/manifests/tag
Then using the Dcker-content-digest from the previous step I did a delete request:
curl --cacert ~/Documents/certificates//ca.pem --key ~/Documents/certificates//key.pem --cert ~/Documents/certificates/certificate.p12 --pass certpass --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -X DELETE https://myprivateregisty/v2/imagename/manifests/dockercontentdigestgotfrompreviousstep
I got this error:
{"errors":[{"code":"MANIFEST_UNKNOWN","message":"manifest unknown"}]}
In all likelihood, it means, that you have deleted the manifest, and this is right first step. To delete actual data from disk, you need to run docker registry garbage collector on registry host machine.
docker exec -it registry bin/registry garbage-collect /etc/docker/registry/config.yml
The info is from that comment
Also, as some adv, I want to propose you to check my docker registry web UI =) There is the possibility to delete an images from registry right with that UI.

Resources