3

I building a CLI python application that takes a CSV file as argument input and various options

Example: rexona [-h] [-v | -q] [-o] filepath

My question is how to dockerize it in a way that when I run my docker file I can run the above command and pass in the specified arguments?

My current docker file

FROM python:3
WORKDIR .
COPY . .
CMD ["python","app.py"]

Should I also install an os image such as ubuntu, so that I can run cmd commands or is there a way to that in docker?

Apologies, I'm still new to docker. Thanks

asked Jan 12, 2021 at 6:00
1
  • I'd run this in a host Python virtual environment in most cases. The required docker command-line options to make this work will probably be longer than the actual command line to start your program, the container form will require root-equivalent privileges to run, and you'll need to install Docker to run it (where most Linux/MacOS systems have Python already). Commented Jan 12, 2021 at 11:29

2 Answers 2

4

You need to add entry point for eg:

# Base image of the docker container
FROM python:3
# Copy the contents of the repo into the /app folder inside the container
COPY . /app
# Update the current working directory to the /app folder
WORKDIR /app
# Add your CLI's installation setups here using the RUN command
# If you have any pip requirements you can do that here
# RUN pip install --user -r requirements.txt
# Provdide a path to your cli apps executable
ENTRYPOINT [ "python", "script.py" ]
answered Jan 12, 2021 at 6:18
Sign up to request clarification or add additional context in comments.

Comments

2

I also run into similar senario i solved it using Entry point

ENTRYPOINT [ "python", "script.py" ]

run script

docker run arg1 arg2 arg3...

And then in Python Program

import sys
print(sys.argv)
answered Jan 12, 2021 at 6:13

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.