Python script in docker not interactive

  docker, python

I am trying to execute python script in docker, and allow inputs from the terminal to the dockr

Dockerfile:

FROM python:3
WORKDIR /app
USER root
ADD . .
RUN chmod a+x ./main.py
RUN chmod a+x ./run.sh
ENTRYPOINT ["sh","./run.sh"]

main.py:

print("Begin script")
x = input("Enter your name")
print("you entered")
print(x)

run.sh:

#! usr/bin/env bash
timeout --signal=SIGTERM 500 python3 main.py
exit $?

Docker build and run commands:

docker image build . -t testimg --rm
docker run -ti  --name testimg testimg

terminal logs:

Begin script
Enter your namejohn

It gets stuck, it does not register what I typed into my terminal "john"

Source: Python Questions

LEAVE A COMMENT