docker python脚本无法正确执行

2024-10-02 04:32:59 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行我的集装箱时,我试图运行“docker.py从根目录(“/”)中使用“/usr/bin/python”。我已经检查了源图像以确保python二进制文件存在,我已经上传了docker.py到docker映像,并使用该二进制文件成功运行它。但是,当我尝试创建映像并运行映像时,我得到了这个错误(“eoferor:EOF when reading a line”),我不知道这意味着什么,也不知道从哪里开始。感谢任何帮助。提前谢谢!在

猫docker.py

#!/usr/bin/python
my_name = raw_input("Enter your name: ")
print my_name
quit()

cat Dockerfile

^{pr2}$

docker构建。

Sending build context to Docker daemon  175.8MB
Step 1/3 : FROM python:2.7
 ---> b1d5c2d7dda8
Step 2/3 : ADD docker.py /docker.py
 ---> f55a19158773
Step 3/3 : CMD ["/usr/bin/python", "/docker.py"]
 ---> Running in b830da5a2f5b
 ---> ef5b878d203f
Removing intermediate container b830da5a2f5b
Successfully built ef5b878d203f
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

docker运行ef5b878d203f

Enter your name: Traceback (most recent call last):
  File "/docker.py", line 2, in <module>
    my_name = raw_input("Enter your name: ")
EOFError: EOF when reading a line

Tags: andtodockernamepyyourbinmy
1条回答
网友
1楼 · 发布于 2024-10-02 04:32:59

问题是你的docker.py脚本需要输入。正如@Klaus D.所评论的,对于raw_input命令,您需要在一个交互式shell中。当您在docker容器中运行时,没有交互式shell,所以当您运行raw_input时,它只会意外地结束该命令,因此会收到错误。在

一旦您启动了容器,从用户的角度来看,它就像一个小虚拟机,您可以与它进行的唯一交互是通过在容器本身中设置的方法。或使用以下方法进入容器:

docker exec -it CONTAINER_HASH /bin/bash

从那里你有一个交互式shell,如果你像那样登录,你可以运行

^{pr2}$

就像你所期望的那样。在

相关问题 更多 >

    热门问题