Reputation: 1
I am using bash script to pull docker images from one Azure Container registry (ACR) to push it to another ACR but getting below error, only the last image from the text file is getting pull/push. I'd input list of multiple docker images in the text file.
'Error parsing reference: "aaaaaaaaaa.azurecr.io/alpine:x.xx.x\r" is not a valid repository/tag: invalid reference format'.
Below is the script I am using it.
#!/bin/sh
FILE_NAME="linux-images.txt"
SOURCE_ACR_NAME=""
SOURCE_USER_NAME=""
SOURCE_PASSWORD=""
DEST_ACR_NAME=""
DEST_USER_NAME=""
DEST_PASSWORD=""
docker login -u "$SOURCE_USER_NAME" -p "$SOURCE_PASSWORD" "$SOURCE_ACR_NAME"
docker login -u "$DEST_USER_NAME" -p "$DEST_PASSWORD" "$DEST_ACR_NAME"
for Image in `cat $FILE_NAME`
do
SOURCE_IMAGE="$SOURCE_ACR_NAME/$Image"
DEST_IMAGE="$DEST_ACR_NAME/$Image"
echo "Images to import from $SOURCE_IMAGE to $DEST_IMAGE"
docker pull "$SOURCE_IMAGE"
docker tag "$SOURCE_IMAGE" "$DEST_IMAGE"
docker push "$DEST_IMAGE"
done
docker logout
Upvotes: 0
Views: 104
Reputation: 7614
'Error parsing reference: "aaaaaaaaaa.azurecr.io/alpine:x.xx.x\r" is not a valid repository/tag: invalid reference format'.
If you are running the script in windows, you will get that error caused carriage return characters (\r
) which are causing errors in a Unix environment.
To resolve the issue, install dos2unix on windows by using below commands.
wsl --install
sudo apt-get update
sudo apt-get install dos2unix
ACR.text
image1/hello-world:v1
image1/mcr.microsoft.com/windows/servercore:v1
ACR.sh
#!/bin/bash
# Source ACR details
ACR_S="venkataccr.azurecr.io"
ACR_U="venkataccr"
ACR_P="12233333"
# Destination ACR details
D_ACR_S="destinationacr1.azurecr.io"
D_ACR_U="destinationacr1"
D_ACR_P="1233444444"
docker login $ACR_S -u $ACR_U -p $ACR_P
docker login $D_ACR_S -u $D_ACR_U -p $D_ACR_P
images_file=/root/ACr/ACR.text
while IFS= read -r image; do
if [[ ! -z "$image" ]]; then
echo "Processing image: $image"
docker pull "$ACR_S/$image"
docker tag "$ACR_S/$image" "$D_ACR_S/$image"
docker push "$D_ACR_S/$image"
fi
done < "$images_file"
Output:
Reference: How to install Linux on Windows with WSL
Upvotes: 0