0

I edit my Dockerfile from the feedback I received. I run my python script with args python3 getappVotes.py --abc 116 --xyz 2 --processall This is my Dockerfile. I can build successfully but not sure how I can pass above args during docker run. Arguments are optional.

FROM python:3.7.5-slim
WORKDIR /usr/src/app
RUN python -m pip install \
        parse \
        argparse \
        datetime \
        urllib3  \
        python-dateutil \
        couchdb  \
        realpython-reader
RUN mkdir -p /var/log/appvoteslog/
COPY getappVotes.py .
ENTRYPOINT ["python", "./getappVotes.py"]
CMD ["--xx 116", "--yy 2", "--processall"]
6
  • 1
    You seem to be installing standard library packages with pip, that's not necessary. Typically you'd include a requirements.txt so you don't have to list them all out. Commented Jan 12, 2021 at 19:54
  • @jonrsharpe Thanks!! I will do that once I figure out the issue. Commented Jan 12, 2021 at 19:56
  • You need to use both ENTRYPOINT (for the program and mandatory arguments) and CMD (for optional arguments). Your question is certainly a duplicate, BTW ;-) Commented Jan 12, 2021 at 20:06
  • 1
    @ErikMD I updated my Dockerfile and now I am getting this error - error: unrecognized arguments: --xx 116 --yy 2 Commented Jan 13, 2021 at 14:48
  • 1
    @user557657 OK so I'll comment on your Dockerfile in an answer below. Commented Jan 13, 2021 at 15:17

1 Answer 1

1

As mentioned in the comments, for your use case, you need to use both ENTRYPOINT (for the program and mandatory arguments) and CMD (for optional arguments).

More precisely, you should edit your Dockerfile in the following way:

FROM python:3.7.5-slim
WORKDIR /usr/src/app
RUN python -m pip install \
        parse \
        argparse \
        datetime \
        urllib3  \
        python-dateutil \
        couchdb  \
        realpython-reader
RUN mkdir -p /var/log/appvoteslog/
COPY getappVotes.py .
ENTRYPOINT ["python", "./getappVotes.py"]
CMD ["--xx", "116", "--yy", "2", "--processall"]

(as from a shell perspective, --xx 116 is recognized as two separated arguments, not a single argument)

For more details:

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

1 Comment

I tried both but didnt separate the arguments and thats why it was failing. Let me try. Thanks!!

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.