简体   繁体   English

Docker找不到目录

[英]Docker can't find directory

I want to create a docker for my scripts.我想为我的脚本创建一个泊坞窗。

My dockerfile is =我的dockerfile是 =

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,设置此 Dockerfile 后,

sudo docker build -t image_name_test:tag_name_test .

my image id : 72e5ee15f5a5我的图像 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 ?为什么我的 docker 找不到目录 main.py ?

Thank you for your time.感谢您的时间。

Here is my files:这是我的文件:

这是我的文件

You're quoting both the filename and its argument as a single word;您将文件名及其参数作为一个单词引用; it's the same effect as running without Docker和没有 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.这会导致 Python 解释器查找该名称(包括空格和参数)作为要运行的脚本的文件名。

If you're using the JSON-array "exec form", you need to split each word into a separate JSON array element.如果您使用 JSON 数组“执行形式”,则需要将每个单词拆分为单独的 JSON 数组元素。

This particular ENTRYPOINT / CMD split doesn't really make sense and I'd combine both halves into a single CMD .这种特殊ENTRYPOINT / CMD拆分并没有真正意义,我会将两半合并成一个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更好的是,如果您以“shebang”行开始脚本,作为脚本的第一行

#!/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那么你可以完全省略python3解释器

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM