user1801934 user1801934 - 3 months ago 47
Bash Question

How to pass arguments to Shell Script through docker run

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

BMW BMW
Answer

@user1801934, are you sure @Gilles Quenot's answer is correct?

put the arg1 into Dockerfile directly, is that your request?

Here is my answer.

Update file.sh

#!/usr/bin/env bash
echo $1

using the exist Dockerfile

Build the image:

docker build -t test .

run the image with argument abc or xyz or something else.

docker run -ti test /file.sh abc

docker run -ti test /file.sh xyz
Comments