I'm very new to both python and docker, but nevertheless I'm trying to create a Docker container for password-generator app I wrote. But after building the app, I am getting error messages that I don't know if they are related to the python code or to the way I built the Docker.
I expected the app to run normally but instead I got this error message:
URL? >> Traceback (most recent call last):
File "pwd1.py", line 6, in <module>
url = input('URL? >> ')
EOFError: EOF when reading a line
This was never a problem in my computer or in Sublime, where the app always functioned normally.
This was the original code (the "(...) in the end of variable "a", is due to Nano not transcribing the rest of the carachters outside the visible screen):
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()
After researching the error I altered the code to this:
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()
But I get the same error message. I tried this code on sublime, the computer and on online editors and not one complained about it.
It's because of this thqat I started thinking if it had something to do with my Docker files.
This is my 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"]
I followed the directions explained here https://docs.docker.com/get-started, and when I try to run the app with "sudo docker run pwdmanager", I get the aforementioned error message.
Any help would be greatly appreciated
答案 0 :(得分:2)
Please run your Docker container using the -i flag (interactive).
Example:
docker run -i -t <your-options>
This, of course, will leave the biggest problem on the table, as correctly pointed out in a comment from @MisterMiyagi:
input asks for input on stdin, for example from a terminal. How do you provide this in the container? Your docker file seems not to include any input for pwd1.py
In order to solve this I would suggest you to read this answer on SO.
Or, imho, just skip using Docker for this use case.