I have a python file called perf_alarm_checker.py
, this python file requires two command line arguments: python perf_alarm_checker.py -t something -d something
, the Dockerfile looks like this:
# Base image
FROM some base image
ADD perf_alarm_checker.py /perf-test/
CMD python perf_alarm_checker.py
How to pass the two command line arguments, -t
and -d
to docker run
? I tried docker run -w /perf-test alarm-checker -t something -d something
but doesn't work.
You cannot use -t
and -d
as you intend, as those are options for docker run
.
-t
starts a terminal.
-d
starts the docker container as a daemon.
For setting environment variables in your Dockerfile use the ENV
command.
ENV <key>=<value>
See the Dockerfile reference.
Another option is to pass environment variables through docker run
:
docker run ... -e "key=value" ...
See the docker run reference.
Those environment variables can be accessed from the CMD
.
CMD python perf_alarm_checker.py -t $ENV1 -d $ENV2
Use an ENTRYPOINT instead of CMD and then you can use command line options in the docker run like in your example.
ENTRYPOINT ["python", "perf_alarm_checker.py"]