How to pass arguments to Shell Script through docker run How to pass arguments to Shell Script through docker run bash bash

How to pass arguments to Shell Script through docker run


with this script in file.sh

#!/bin/bashecho Your container args are: "$@"

and this Dockerfile

FROM ubuntu:14.04COPY ./file.sh /ENTRYPOINT ["/file.sh"]

you should be able to:

% docker build -t test .% docker run test hello worldYour container args are: hello world


Use the same file.sh

#!/bin/bashecho $1

Build the image using the existing Dockerfile:

docker build -t test .

Run the image with arguments abc or xyz or something else.

docker run -ti --rm test /file.sh abcdocker run -ti --rm test /file.sh xyz


With Docker, the proper way to pass this sort of information is through environment variables.

So with the same Dockerfile, change the script to

#!/bin/bashecho $FOO

After building, use the following docker command:

docker run -e FOO="hello world!" test