Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker: invalid reference format in shell script

Tags:

bash

shell

docker

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?

like image 414
user1775718 Avatar asked Jul 24 '17 12:07

user1775718


People also ask

How to solve docker invalid reference format?

How to fix - docker: invalid reference format: repository name must be lowercase? The simplest way to fix the issue by change the image to jhooq-docker-demo so that there is no uppercase character in the image name . docker build -t jhooq-docker-demo .

What is Docker invalid reference format?

"docker: invalid reference format" messageThe current directory ( %CD% ) or user profile path ( %USERPROFILE% ) in the command contains a space. To fix the problem, put double quotation marks around any references to a path that contains one or more spaces.


1 Answers

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 immediately after the -it parameter and so re arrange your run command.

like image 52
Raman Sailopal Avatar answered Nov 02 '22 06:11

Raman Sailopal