我对python和docker都很陌生,但我还是尝试为我编写的密码生成器应用程序创建一个Docker容器。但是在构建这个应用程序之后,我收到了错误消息,我不知道它们是否与python代码或我构建Docker的方式有关。
我希望应用程序能够正常运行,但我得到了以下错误消息:
URL? >> Traceback (most recent call last):
File "pwd1.py", line 6, in <module>
url = input('URL? >> ')
EOFError: EOF when reading a line这从来不是我的电脑或崇高的问题,那里的应用程序总是正常工作。
这是原来的代码(变量"a“结尾的”(.)“,是因为Nano没有转录可见屏幕外的其他货车):
import random
a = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G','g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p'(...)]
file = open('/home/mic/python/password-generator/list.py', 'a')
url = input('URL? >> ')
file.write(url)
file.write(' - ')
k: int = int(input('How long? >> '))
b = (str(''.join(random.sample(a, k))))
print(b)
file.write(b)
file.write('\n')
file.close()在研究了错误之后,我将代码修改为:
import random
a = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G','g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p'(...)]
file = open('list.py', 'a')
url = input('URL? >> ')
while True:
try:
line = input()
except EOFError:
print ("EOFError")
file.write(url)
file.write(' - ')
k: int = int(input('How long? >> '))
b = (str(''.join(random.sample(a, k))))
print(b)
file.write(b)
file.write('\n')
file.close()但我也收到了同样的错误信息。我在“崇高”、“电脑”和“在线编辑”上尝试了这段代码,但没有人抱怨过。
正因为如此,我开始思考这是否与我的Docker文件有关。
这是我的Dockerfile:
# Use an official Python runtime as a parent image
FROM python:3.7.3
# Set the working directory to /app
WORKDIR /password
# Copy the current directory contents into the container at /app
COPY . /password
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "pwd1.py"]我遵循这里解释的https://docs.docker.com/get-started的说明,当我尝试使用“”运行这个应用程序时,我得到了前面提到的错误消息。
任何帮助都将不胜感激。
发布于 2019-05-31 11:42:30
请使用-i标志(交互式)运行您的Docker容器。
示例:
docker run -i -t <your-options>当然,正如@MisterMiyagi的评论所正确指出的那样,这将留下最大的问题:
输入请求stdin上的输入,例如从终端输入。您如何在容器中提供这个?您的停靠文件似乎不包括pwd1.py的任何输入。
为了解决这个问题,我建议您阅读this answer on SO。
或者,imho,只需跳过在这个用例中使用Docker。
https://stackoverflow.com/questions/56394362
复制相似问题