user1801934 user1801934 - 1 year ago 181
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:

echo $1

Dockerfile looks like this:

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

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

Answer Source

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

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

Here is my answer.


#!/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 / abc

docker run -ti test / xyz
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download