2

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?

0

1 Answer 1

3

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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.