简体   繁体   English

在Docker中的入口点运行命令不会输出文件错误

[英]Run command on entrypoint in docker outputs no file errors

On a simple dockerfile: 在简单的dockerfile上:

FROM python:3
ENV PYTHONUNBUFFERED 1
WORKDIR /code/

If I run: 如果我运行:

docker build -t my_image .
docker run -v ~/Downloads/data/:/home -it -d my_image # mount data folder inside home
docker exec -it container_id  sh -c  "python script.py -i /home/db.sqlite"

Everything runs ok. 一切正常。 But I would like to run the script.py on run so that there is no need for an exec command. 但是我想在运行时运行script.py ,因此不需要exec命令。

So I added to the dockerfile: 所以我添加到dockerfile中:

ENTRYPOINT ["python script.py -i /home/db.sqlite"]

But when I run my container now it fails with a file or folder not found error at python script.py 但是当我现在运行容器时,它失败,并在python script.py出现文件或文件夹未找到错误

I think the problem is how the ENTRYPOINT syntax works. 我认为问题在于ENTRYPOINT语法如何工作。 Your using the exec-form and it does not find the binary (it uses the whole command line as path to the binary). 您使用的是exec-form,但找不到二进制文件(它使用整个命令行作为二进制文件的路径)。

From https://docs.docker.com/engine/reference/builder/#entrypoint : https://docs.docker.com/engine/reference/builder/#entrypoint

ENTRYPOINT has two forms: ENTRYPOINT有两种形式:
ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred) ENTRYPOINT [“ executable”,“ param1”,“ param2”](执行表格,首选)
ENTRYPOINT command param1 param2 (shell form) ENTRYPOINT命令param1 param2(shell形式)

So try either: 因此,请尝试:

ENTRYPOINT ["/path/to/python", "script.py", "-i", "/home/db.sqlite"]

Or 要么

ENTRYPOINT python script.py -i /home/db.sqlite

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

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