Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker exec or docker run fails with the input device is not a TTY

Errorthe input device is not a TTY

Short answer

The -t flag asks for a pseudo-terminal, and Docker refuses when your own stdin is not a terminal. That is the case in Jenkins steps, cron, CI jobs and pipes. Drop -t. Keep -i only when you feed the command through stdin.

  • Applies to Docker Engine 28, Docker CLI 28, Jenkins pipeline sh step
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the shell running the command has a terminal on stdin. The test prints yes in a normal terminal and no in CI or cron.

    [ -t 0 ] && echo yes || echo no
  2. 2Match what you see, then jump to its fix

    1. 1The same command works when you type it in an SSH session and fails in the scheduled jobThe job runs without a terminal (Jenkins, cron, CI)Fix
    2. 2The line has a pipe or a < redirect, for example cat dump.sql | docker exec -it ...Input is piped or redirected into the commandFix

What does the error look like?

  • the input device is not a TTY

Cause 1 of 2

The job runs without a terminal (Jenkins, cron, CI)

1Check

-t tells Docker to allocate a pseudo-TTY and connect it to your terminal. A build agent has no terminal, so there is nothing to connect.

grep -rn -E 'docker (exec|run)[^|]* -[a-z]*t' Jenkinsfile *.sh

2Fix

Remove -t. For a command that needs no input, run it with no -i either.

# before
docker exec -it my-container php artisan migrate --force
# after
docker exec my-container php artisan migrate --force

3Verify

Run the job again; the command output appears in the job log.

docker exec my-container echo ok

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 2

Input is piped or redirected into the command

1Check

-i keeps stdin open so the container can read what you pipe in. -t is a different job: it attaches a terminal. Piped input has no terminal, so -t is wrong here.

grep -rn -E '(\||<) *docker|docker[^|]*<' *.sh

2Fix

Use -i alone when data goes in through stdin.

echo hello | docker run --rm -i busybox cat
docker exec -i my-db sh -c 'cat > /tmp/in.txt' < in.txt

3Verify

The container prints or stores exactly what you sent.

echo hello | docker run --rm -i busybox cat

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Write scripts with plain docker exec or docker run; add -it only to commands you type by hand.
  • Use -i without -t when a script pipes data into a container.
  • Add --rm to throw-away docker run commands in CI so stopped containers do not pile up.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.