Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker can't find directory

I want to create a docker for my scripts.

My dockerfile is =

FROM python:3.8

COPY requirements.txt requirements.txt
    
RUN pip install -r requirements.txt
COPY . .

ENTRYPOINT ["python3"]
CMD ["main.py btcusdt"]

after set this Dockerfile,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sudo docker build -t image_name_test:tag_name_test .

my image id : 72e5ee15f5a5

sudo docker run 72e5ee15f5a5

and error is:

python3: can't open file 'main.py btcusdt': [Errno 2] No such file or directory

Why my docker can’t find directory main.py ?

Thank you for your time.
here is my files

>Solution :

You’re quoting both the filename and its argument as a single word; it’s the same effect as running without Docker

python3 "main.py btcusdt"

which causes the Python interpreter to look for that name, including the space and the argument, as the filename of the script to run.

If you’re using the JSON-array "exec form", you need to split each word into a separate JSON array element.

This particular ENTRYPOINT/CMD split doesn’t really make sense and I’d combine both halves into a single CMD. So:

# no ENTRYPOINT
CMD ["python3", "main.py", "btcusdt"]

Better still, if you begin the script with a "shebang" line, as the very very first line of the script

#!/usr/bin/env python3

and make the script executable

# on the host, committed to source control
chmod +x main.py

then you can omit the python3 interpreter entirely

# still no ENTRYPOINT; still split into separate words
CMD ["./main.py", "btcusdt"]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading