1

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

1
  • 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. Commented May 31, 2019 at 11:42

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for taking the time to answer it and you are right. Perhaps this is not the best solution to my problem.
Hi @miguelcaldas! It is my pleasure. If you have found my answer useful please remember to upvote and/or choose it as final answer.
How do I choose it as a final answer?
Hi @miguelcaldas! Here's how (the icon just below my current answer's votes, check the screenshot in this link): meta.stackexchange.com/questions/5234/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.