A simple py program used to build to a docker image, demonstrating the use case of -it
flag.
Clone the repo, inside the greet-prompter
folder, run below command to build the image.
docker build . -t prompter
note that prompter is a image_name you can specify any name
Check the image if it's build, you can use below command.
docker images
docker run prompter
the above command will simply print the printf statement else and EOF file error.
The error you're seeing is because the Docker container is running in a non-interactive mode, which means it can't accept input from the user. The input()
function in Python is trying to read from standard input (stdin), but since there's no input available in a non-interactive Docker container, it raises an EOFError
.
To make the program work, run the docker container in interactive mode and map the docker container terminal to machine terminal.
docker run -it propmter
-i
is option used with docker run
command to interact with running container -t
option is used to map the running container's terminal to the machine's terminal the docker is hosted on.
Voila!