
DevotionGeo
Can someone explain the -t option/flag in docker run command?
I know that -t
flag is used along with -i
flag for getting an interactive shell. But I cannot digest what the man page for docker run command says about this flag, which is the following,
-t, --tty=true|false
Allocate a pseudo-TTY. The default is false.
When set to true Docker can allocate a pseudo-tty and attach to the standard input of
any container. This can be used, for example, to run a throwaway interactive shell.
The default is false.
The -t option is incompatible with a redirection of the docker client standard input.
Things like pseudo-TTY
or “attaching to the standard input”. So if this interactive shell isn’t the standard input for docker container, what is actually the standard input, to which it attaches?
Most Liked

AstonJ
Was curious about this too so did some googling
A pseudo TTY is:
A pseudo TTY (or “PTY”) is a pair of devices — a slave and a master — that provide a special sort of communication channel. The slave device behaves much like the device representing the VT100 or ADM-3A “dumb terminal” that we all have on our desks … or that we might have had a few decades ago.
From: Containers, pseudo TTYs, and backward compatibility [LWN.net]
And how it relates to Docker:
The
-t
option goes to how Unix/Linux handles terminal access. In the past, a terminal was a hardline connection, later a modem based connection. These had physical device drivers (they were real pieces of equipment). Once generalized networks came into use, a pseudo-terminal driver was developed. This is because it creates a separation between understanding what terminal capabilities can be used without the need to write it into your program directly (read man pages onstty
,curses
).So, with that as background, run a container with no options and by default you have a stdout stream (so
docker run | <cmd>
works); run with-i
, and you get stdin stream added (so<cmd> | docker run -i
works); use-t
, usually in the combination-it
and you have a terminal driver added, which if you are interacting with the process is likely what you want. It basically makes the container start look like a terminal connection session.
Source: Confused about Docker -t option to Allocate a pseudo-TTY - Stack Overflow

DevotionGeo
Thank you for the detailed reply!
Now I know how it works under the hood.
Popular Backend topics










Other popular topics










Latest in Backend
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /lua
- /nodejs
- /c
- /slackware
- /julia
- /neovim