0

I am trying to create a Docker container with screen session running some script. Dockerfile contains

CMD screen -S session1 ./testLinux

When I run it in detached mode it closes immediately, saying

Must be connected to a terminal.

How do I run persistent screen session inside detached docker container?

1

I can reproduce this with this Dockerfile:

FROM centos:latest
RUN yum -y install screen && rm -rf /var/cache/yum
CMD screen -S session1 sleep 99999

when I run it with docker run <imageID> I get Must be connected to a terminal.

Screen needs a terminal (tty) to function. The solution is to add -tid to the run flags, from the help:

 -d, --detach                         Run container in background and print container ID
 -i, --interactive                    Keep STDIN open even if not attached
 -t, --tty                            Allocate a pseudo-TTY

See https://docs.docker.com/engine/reference/run/ for reference.

  • This is not a solution, I am trying to run it in detached session. – flanker12X Jul 16 at 6:56
  • Then use -d, added in answer. – Edward Jul 16 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.