“-t --tag”标志的参数无效:引用格式无效

Invalid argument for "-t --tag" flag: invalid reference format

我正在尝试使用此脚本构建 docker 图像:

release.sh

#!/bin/sh

set -e

export ENV="prod"
export REGISTRY_HOST="registry.seesunit.kr"
export IMAGE_PREFIX="$ENV-scim"
export IMAGE_TARGET="web"
export IMAGE_NAME="$REGISTRY_HOST/$IMAGE_PREFIX-$IMAGE_TARGET"
export DOCKER_ROOT="/home/dev-admin/docker"
export DOCKER_PATH="$DOCKER_ROOT/$IMAGE_PREFIX/$ENV-$IMAGE_TARGET"

#echo "CONTAINER > "
#docker container ls | grep $IMAGE_NAME #| grep -Eo "^[^ ]+"
echo "IMAGES > "
docker images | grep $IMAGE_NAME #| grep -Eo "^[^ ]+"

echo "Input IMAGE_TAG :"
read IMAGE_TAG

echo "TAG=$IMAGE_TAG" > $DOCKER_PATH/.env
echo "IMAGE_NAME=$IMAGE_NAME" >> $DOCKER_PATH/.env
echo "TAG=$IMAGE_TAG" > .env
echo "IMAGE_NAME=$IMAGE_NAME" >> .env

docker-compose -f $DOCKER_PATH/docker-compose.yml down

#echo "Q4. DOCKER_ID_USER?"
#read DOCKER_ID_USER
docker rmi -f $IMAGE_NAME:$IMAGE_TAG

docker build -f ./tools/$ENV.Dockerfile -t $IMAGE_NAME:$IMAGE_TAG .

#docker tag $IMAGE_NAME:$IMAGE_TAG $DOCKER_ID_USER/$IMAGE_NAME:$IMAGE_TAG
#docker push $DOCKER_ID_USER/$IMAGE_NAME:$IMAGE_TAG

#docker push $IMAGE_NAME:$IMAGE_TAG

docker-compose -f $DOCKER_PATH/docker-compose.yml up -d

当前容器

CONTAINER ID   IMAGE                                     COMMAND                  CREATED       STATUS       PORTS                                     NAMES
dad647696802   registry.seesunit.kr/prod-scim-web:v_db   "nginx -g 'daemon of…"   2 weeks ago   Up 2 weeks   0.0.0.0:30080->80/tcp, :::30080->80/tcp   prod-web_prod-web_1

当我尝试从命令行 运行 docker build 时:

docker build -f ./tools/$ENV.Dockerfile -t prod-web_prod-web_1:registry.seesunit.kr/prod-scim-web:v_db .

我遇到这样的错误:

invalid argument "prod-web_prod-web_1:registry.seesunit.kr/prod-scim-web:v_db" for "-t, --tag" flag: invalid reference format
See 'docker build --help'.

我运行正在 Windows。

正如上面所说,您的图片 name/tag 无效。

图像名称是 slash-separated。您可以使用包含可选端口号的注册表地址作为前缀。

您的 prod-web_prod-web_1:registry.seesunit.kr/prod-scim-web:v_db 冒号太多。我的猜测是第一位是错误的,你想要的是 registry.seesunit.kr/prod-scim-web:v_db,即你的构建命令应该是

docker build -f ./tools/$ENV.Dockerfile -t registry.seesunit.kr/prod-scim-web:v_db .
-t prod-web_prod-web_1:registry.seesunit.kr/prod-scim-web:v_db
                      ^                                  ^
                      |                                  |

你的 name:tag 参数中有两个冒号 (:)。

Docker 认为您的图片标签是 registry.seesunit.kr/prod-scim-web:v_db,其中包含一个冒号,并且来自 https://docs.docker.com/engine/reference/commandline/tag/:

A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.