Reputation: 1578
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?
Upvotes: 7
Views: 28656
Reputation: 10204
My issue had the same cause addressed by @Raman's answer, but a slightly different cause: Passing in an environment varialbe that had a space in it via
SOMETHING="hello world" # note the space character!
docker run --env SOMETHING=$SOMETHING -it my_image
And the resolution is just to quote the value (which works in Bash, anyway):
docker run --env something="$SOMETHING" -it my_image
Upvotes: 1
Reputation: 12917
The image name should be immediately after the -it
options.
Move the -it
options to the end:
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
Upvotes: 11