6

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?

user1775718
  • 1,499
  • 2
  • 19
  • 32
  • I would suggest that it isn't parsing the -e flags correctly and seeing the NOD_PATH variable as the image name. What happens when you take the -e data out? – Raman Sailopal Jul 24 '17 at 12:42
  • @RamanSailopal Hmmm, it works... – user1775718 Jul 24 '17 at 12:51
  • You just need to re-arrange you docker run command. I've posted an answer – Raman Sailopal Jul 24 '17 at 12:55
  • Not a solution to this problem, but you would also see this error if you set a variable in the script, `FOO="joe foo bar"`, and then reference it in the docker command like this, `-e FOO=$FOO`. The error will arise due to the spaces. You would need to quote the value, `-e FOO="$FOO"`. – wsams Oct 18 '17 at 21:58

1 Answers1

10
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.

Amit Darji
  • 457
  • 3
  • 11
Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18
  • I've amended the answer – Raman Sailopal Jul 24 '17 at 13:08
  • 1
    What's wrong with `docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \ -e SAUCE_USERNAME -e SAUCE_ACCESS_KEY \ -v /tmp/videos:/home/seluser/videos \ -v /var/run/docker.sock:/var/run/docker.sock \ dosel/zalenium start --sauceLabsEnabled true` ? It is also giving same error. – paul Feb 04 '19 at 05:47
  • 1
    Make sure there are no spaces after the `\\`. – wraithie Jul 18 '22 at 12:16