If you’ve used Docker with interactive commands and come across this error:
the input device is not a TTY
…it can be confusing at first. This error often appears when you’re running Docker commands in non-interactive environments or using flags incorrectly.
In this blog post, we’ll explain why this error happens, when to use TTY flags properly, and how to fix it across different environments like terminals, CI/CD pipelines, and scripts.
🔍 What Does “TTY” Mean?
TTY stands for “teletypewriter,” and in the context of Docker and Unix, it refers to an interactive terminal session.
When Docker runs with -t
or --tty
, it tries to allocate a terminal for the container. If no real terminal (TTY) is attached to the input device, Docker throws this error:
the input device is not a TTY
🧪 Common Scenario
You might see this error when running:
docker exec -it my-container sh
But the command is run from:
- A non-interactive script (like a shell script or cron job)
- A CI/CD pipeline (like GitHub Actions or GitLab CI)
- A command-line terminal with no TTY session
✅ How to Fix It
✅ 1. Remove -t
(--tty
) in Non-Interactive Environments
If you’re not using an interactive terminal, remove the -t
flag.
docker exec -i my-container sh
Use -i
only to keep STDIN open, which is typically what scripts or pipelines need.
✅ 2. Run Interactively Only When Necessary
If you’re running Docker commands interactively (like for debugging or development), keep -it
. But for scripts or CI jobs, avoid -t
unless you know you’re in a real terminal.
✅ 3. Use Conditional Logic in Scripts
If your script might run in both interactive and non-interactive modes, use tty
or test -t
to detect if STDIN is a terminal:
if [ -t 1 ]; then
docker exec -it my-container sh
else
docker exec -i my-container sh
fi
This ensures you avoid errors in automation environments.
✅ 4. Fix It in CI/CD Pipelines
In CI environments, avoid using -t
unless the runner supports it.
Example (GitHub Actions):
- run: docker exec -i my-container some-command
For GitLab CI, also drop the -t
unless you’re in a script:
section running in a true shell.
✅ 5. Use docker run
Instead?
If you’re using docker exec
, remember it only applies to running containers. For new containers, use:
docker run -i my-image command
…and skip the -t
if not needed.
📝 Conclusion
The Docker error "the input device is not a TTY"
happens when Docker expects an interactive terminal—but none exists. The solution is simple: remove the -t
flag when running in non-interactive environments like scripts or pipelines.
🔑 Quick Summary
Situation | Use Flag(s) | Notes |
---|---|---|
Interactive terminal | -it | For debugging or local usage |
Non-interactive script | -i only | Avoid -t |
CI/CD pipelines | -i only | Most runners don’t support TTY |
Uncertain environment (script) | test -t condition | Dynamically choose based on environment |