[英]Docker run Python File on startup
First of all, I'm very new to Docker, so if my general idea of how this should work is stupid, then please tell me :) I created a Dockerfile which looks like this:首先,我对 Docker 很陌生,所以如果我对它应该如何工作的一般想法很愚蠢,那么请告诉我:) 我创建了一个 Dockerfile,它看起来像这样:
FROM nodered/node-red:1.2.1
COPY./retrieveNewFlow.py /home/retrieveNewFlow.py
ENTRYPOINT [ "/bin/bash" ]
CMD [ "python3", "/home/retrieveNewFlow.py" ]
I want to execute the retrieveNewFlow.py Python Script every time the container starts.我想在每次容器启动时执行retrieveNewFlow.py Python Script。 But I get the following error message:但我收到以下错误消息:
/usr/bin/python3: /usr/bin/python3: cannot execute binary file
Can anybody image what i've done wrong?任何人都可以想象我做错了什么吗?
Change the ENTRYSCRIPT
in your dockerfile
更改ENTRYSCRIPT
中的dockerfile
from ENTRYPOINT [ "/bin/bash" ]
从ENTRYPOINT [ "/bin/bash" ]
to ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
到ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
The ENTRYPOINT
and CMD
are combined together into a single command , so the main container command becomes ENTRYPOINT
和CMD
组合成一个命令,因此主容器命令变为
/bin/bash python3 /home/retrieveNewFlow.py
This instructs Bash to try to run the Python interpreter as a shell script;这会指示 Bash 尝试将 Python 解释器作为 shell 脚本运行; since it's not, you get the error you see.因为它不是,你会看到你看到的错误。
You are not required to have an ENTRYPOINT
, and you should remove it here.您不需要拥有ENTRYPOINT
,您应该在此处将其删除。 Leave the CMD
as you have it.保留CMD
。
# No ENTRYPOINT
CMD ["python3", "/home/retrieveNewFlow.py"]
This will cause the main container command to be the Python script, without unnecessarily introducing a bash
wrapper.这将导致主容器命令成为 Python 脚本,而无需引入bash
包装器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.