dockerdocker-imageacrdocker-pushdocker-tag

Move docker images from one acr to another (docker images --format option not executing docker tag , docker push )


I am trying to move images from one acr to another acr. (also any alternate method to do this please suggest)

I am using shell script and I have declared variables for one image to test it ( however i have 20+ images ) "sourceacr" image="myimage" minimum_version="1.0.0" "targetacr"

steps followed:

docker pull $sourceacr/image --all-tags

then filter since the minimum version , re-tag it and push to target acr

my command is

docker images $sourceacr/$image --filter "since=$sourceacr/$image:$minimum_version" --format "docker tag {{.Repository}}:{{.Tag}} $targetacr/$image:{{.Tag}} | docker push $targetacr/$image:{{.Tag}}"

I get output as command that is used after --format option but it doesn't execute the tag and push commands. Any help is appreciated!

current output:

docker tag source.azurecr.io/myimage:1.0.0 target.azureacr.io/myimage:1.0.0 | docker push target.azureacr.io/myimage:1.0.0

Solution

  • The way you have your command, it's basically outputting the docker commands in the terminal. You need to execute them as command, try like this:

    docker images $sourceacr/$image  --filter "since=$sourceacr/$image:$minimum_version" --format "docker tag {{.Repository}}:{{.Tag}} $targetacr/$image:{{.Tag}} | docker push $targetacr/$image:{{.Tag}}" | bash
    

    or using shell:

    docker images $sourceacr/$image  --filter "since=$sourceacr/$image:$minimum_version" --format "docker tag {{.Repository}}:{{.Tag}} $targetacr/$image:{{.Tag}} | docker push $targetacr/$image:{{.Tag}}" | sh