When working with Docker, especially when running interactive commands or scripting container workflows, you might encounter this error:
the input device is not a TTY
This cryptic message often catches developers off guard, but it has a clear cause — and a straightforward fix.
In this post, we’ll explain what this error means, when it typically appears, and how to resolve it.
📌 What Does “The input device is not a TTY” Mean?
TTY stands for teletypewriter, which refers to a terminal session or interactive shell. Docker uses TTYs to allocate a pseudo-terminal so you can interact with containers directly.
This error usually occurs when:
- You’re using the
-t(or--tty) flag in a non-interactive environment (like a script or a CI/CD pipeline). - The Docker CLI is expecting a TTY but can’t find one.
🐳 Common Scenario That Triggers the Error
You may see this error when running a Docker command like:
docker exec -it container_name bash
in an environment where stdin is not connected to a terminal (e.g., running inside another script or cron job).
✅ How to Fix It
🔹 1. Remove the -t or -it Flags in Non-Interactive Environments
If you’re running the command in a non-interactive context (like a script), drop the -t flag:
docker exec -i container_name bash -c "your_command"
If you don’t need to interact with the terminal, don’t use -t.
-i: Keeps STDIN open-t: Allocates a TTY (only needed for interactive sessions)
🔹 2. Add a TTY in Interactive Sessions
If you’re using Docker in an interactive terminal (like a shell), make sure to use both flags:
docker exec -it container_name bash
Use this when you want to open a shell inside the container manually.
🔹 3. Use Conditional Scripts for CI/CD
In CI/CD tools like GitLab CI or Jenkins, avoid using -t since these environments typically don’t have an interactive terminal.
Wrong (causes TTY error):
docker exec -it app_container ./deploy.sh
Correct:
docker exec -i app_container ./deploy.sh
Or, conditionally detect the terminal:
if [ -t 1 ]; then
docker exec -it container bash
else
docker exec -i container bash
fi
🔍 How to Know If You’re in a TTY
Run this in a shell:
[ -t 1 ] && echo "Interactive terminal" || echo "Not a TTY"
If it prints “Not a TTY,” avoid using -t.
🧪 Bonus: When Using docker run
When starting new containers with docker run, the same logic applies:
- For interactive use:
docker run -it ubuntu - For scripting (no TTY):
docker run -i ubuntu echo "Hello from container"
🔚 Summary
| Use Case | Command |
|---|---|
| Interactive shell | docker exec -it container bash |
| Scripted commands | docker exec -i container command |
| CI/CD pipelines | Avoid -t; use -i only |
🧭 Conclusion
The “input device is not a TTY” error is a classic case of Docker trying to open a terminal where none exists. Understanding when to use -it versus -i helps avoid this and makes your Docker workflows more robust — especially in scripts and automation.