31

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.

2 Answers 2

63

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

Sign up to request clarification or add additional context in comments.

1 Comment

This should be the correct answer... Not sure why the other answer is marked as green...
24

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.