2

I have a very simple python script. I am trying to use it in a docker container.

Python file (computer.py)

import datetime
print("Welcome to virtual assistant.")
name = input("What is your name? ")
print("Welcome " + name)
def time():
print(datetime.datetime.now())
command = input("Would you like to know the time " + name + "?")
if command == "yes":
print(time())

And My docker file looks like this.(Docker)

FROM python:3

ADD computer.py /

CMD [ "python", "./computer.py" ]

Then I ran

docker build -t python-barcode .

Then

run python-barcode

I get this error

Traceback (most recent call last):
  File "./computer.py", line 4, in <module>
    name = input("What is your name? ")
EOFError: EOF when reading a line
Welcome to virtual assistant.
What is your name? %

It seems to run the code up untill I ask for input? Not even sure what would cause that. Any help would be greatly appreciated.

2 Answers 2

2

When you run a container with docker run, stdin is by default not connected, so anything that attempts to read interactive input will fail. You probably want to run:

docker run -it python-barcode

The -i leaves stdin connected, and the -t allocates a tty which is what you normally want to interactive input.

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

2 Comments

Thank you that worked! Are the -i and -t just docker arguments? just so I can look up a comprehensive list.
That's correct; you can find those documented in the docker run reference.
0

you shold run the container in interactive mode with the -i and -t

docker run -it python-barcode

Comments

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.