I am trying to compile and run python code in Docker.
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"]
run.sh
#! usr/bin/env bash
timeout --signal=SIGTERM --foreground 500 python3 main.py
exit $?
python code (using docker sdk for python):
client = docker.from_env()
client.images.build(path="./Dockerimagefolder/",tag="sample322")
container = client.containers.create(image="sample322", stdin_open = True)
container.start()
time.sleep(5)
s = container.attach_socket(params={'stdin': 1, 'stream': 1})
s.send('test'.encode())
container log:
Begin script
Enter your nameyou entered
test
as you can see, "you entered" is not shown on the next line, instead, it's placed in the same line as input. It also doesn't show the input that was sent i.e test
I am also unable to get the output, the log I shown above is from the docker app
print(container.logs())