Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.8k views
in Technique[技术] by (71.8m points)

dockerfile - How to pass args to docker run for python?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...