docker exec or docker run fails with the input device is not a TTY
the input device is not a TTYShort 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.
Fix it fast
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 no2Match what you see, then jump to its fix
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 *.sh2Fix
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 --force3Verify
Run the job again; the command output appears in the job log.
docker exec my-container echo okConfirmed by docs.docker.com
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[^|]*<' *.sh2Fix
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.txt3Verify
The container prints or stores exactly what you sent.
echo hello | docker run --rm -i busybox catConfirmed by docs.docker.com
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
Servers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fix