How to pass arguments to Shell Script through docker run

Akash Mehta picture Akash Mehta · Sep 22, 2015 · Viewed 237.4k times · Source

I am new to the docker world. I have to invoke a shell script that takes command line arguments through a docker container. Ex: My shell script looks like:

#!bin/bash
echo $1

Dockerfile looks like this:

FROM ubuntu:14.04
COPY ./file.sh /
CMD /bin/bash file.sh

I am not sure how to pass the arguments while running the container

Answer

Partly Cloudy picture Partly Cloudy · Oct 28, 2016

with this script in file.sh

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

and this Dockerfile

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

you should be able to:

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