Search code examples
dockerartifactory

Unable to copy docker image in JFrog Artifactory from one repo to a target repo


We have an Artifactory server to host our Docker images. I am trying to effectively re-tag one of my Docker images using the JFrog API. I know I could do this with a simple docker tag and docker push, but wanted to see how to do this more directly with the Artifactory API. Unfortunately I am running into a snag. Here's the API call I'm trying to make:

curl -X POST --user 'my@user.com:MyAPIKey' -H "Content-Type: application/json" --data \
  '{"targetRepo": "docker-local", "dockerRepository": "docker-local", "tag": "my/docker/image/original", "targetTag": "my/docker/image/new", "copy": true}' \
  https://www.myartifactoryserver.com/api/docker/docker-local/v2/promote

But this call returns the following error:

{
  "errors" : [ {
    "status" : 400,
    "message" : "'targetTag' tag value is invalid."
  } ]
}

I'm not sure what I'm doing wrong here, especially since I am able to perform this same copy using the UI. How do I do it with the API?


Solution

  • The problem is with the parameter values you are using for the dockerRepository, tag and targetTag parameters.
    Here is an example of how to retag the image hello-world:latest (stored in the docker-local repository) as hello-world:1.0 :

    POST api/docker/docker-local/v2/promote
    
    {
      "repository" : "docker-local", // Source Artifactory repository
      "dockerRepository" : "hello-world", // Source Docker repository
      "targetRepo" : "docker-local", // Target Artifactory repository
      "tag" : "latest", // Source tag name
      "targetTag" : "1.0" // Target tag name
    }
    

    Here is an example of a curl command for sending the above request:

    curl -uuser:password -XPOST -H"content-type: application/json"  -d "{\"repository\" : \"docker-local\", \"dockerRepository\" : \"hello-world\", \"targetRepo\" : \"docker-local\", \"tag\" : \"latest\", \"targetTag\" : \"1.0\"}" https://myserver.jfrog.io/artifactory/api/docker/docker-local/v2/promote
    

    Please notice both Artifactory and Docker use the term "repository", but each uses it in a different way.
    A Docker repository is a hosted collection of tagged images that, together, create the file system for a container
    A Docker registry is a host that stores Docker repositories
    An Artifactory repository is a hosted collection of Docker repositories, effectively, a Docker registry in every way, and one that you can access transparently with the Docker client.