Home > Blockchain >  Docker can't find directory
Docker can't find directory

Time:07-16

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,

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:

here is my files

CodePudding user response:

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