简体   繁体   中英

docker: invalid reference format in shell script

I'm trying to create a shell script to run a docker container and am struggling. My script is like this:

#!/bin/bash

if [ "$1" == "" ]; then
    echo "Usage > run.sh IMAGE NAME"
    echo
    echo "i.e. ./build.sh cd2:0.0.49"
    exit
fi

echo $1

docker run -it --rm \
-e NODE_PATH='./src'\
-e NODE_HOST='0.0.0.0'\
-e NODE_ENV='production'\
-e DOCKER=true\
-e PORT='8080'\
-e STAGING=true\
-e SENDGRID_API_KEY='<redacted>'\
-p 8080:8080 $1

When I run: bash run.sh cd2:0.0.50

I get: docker: invalid reference format: repository name must be lowercase.

Even if I do bash run.sh cd:0.0.50 it still fails ( echo $1 results in cd2:0.0.50 ).

If I run docker run -it --rm -p 8080:8080 cd2:0.0.50 from the command line it works...

Can anyone help?

docker run \
-e NODE_PATH='./src' \
-e NODE_HOST='0.0.0.0' \
-e NODE_ENV='production' \
-e DOCKER=true \
-e PORT='8080' \
-e STAGING=true \
-e SENDGRID_API_KEY='<redacted>' \
-p 8080:8080 --rm -it $1

The image name should be after the -it parameter and so re arrange your run command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM