Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLI Application with docker

Tags:

python

docker

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

like image 588
Omar Jarkas Avatar asked Jun 13 '26 10:06

Omar Jarkas


2 Answers

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

like image 90
Prabhat Kumar Sahu Avatar answered Jun 15 '26 22:06

Prabhat Kumar Sahu


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)
like image 34
user13966865 Avatar answered Jun 16 '26 00:06

user13966865



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!