how to pass command line arguments to a python scr

2019-02-09 09:54发布

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.

标签: docker
2条回答
神经病院院长
2楼-- · 2019-02-09 10:13

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"]

查看更多
地球回转人心会变
3楼-- · 2019-02-09 10:17

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
查看更多
登录 后发表回答