DevotionGeo

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

AstonJ

Was curious about this too so did some googling :blush:

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 on stty , 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

DevotionGeo

Thank you for the detailed reply! :slight_smile:
Now I know how it works under the hood.

Popular Backend topics Top

PragmaticBookshelf
The next step in the evolution of user interfaces is here. Chatbots let your users interact with your service in their own natural langua...
New
PragmaticBookshelf
Classroom-tested by tens of thousands of students, this new edition of the bestselling intro to programming book is for anyone who wants ...
New
New
ManningBooks
Deep Learning with Python, Second Edition is a comprehensive introduction to the field of deep learning using Python and the powerful Ker...
New
ManningBooks
Rust in Action introduces the Rust programming language by exploring numerous systems programming concepts and techniques. You'll be lear...
New
TwistingTwists
Hello Folks, I am a novice developer from India. Intending to learn Elixir and web apps (phoenix framework). What are things that I MUS...
New
PragmaticBookshelf
Use WebRTC to build web applications that stream media and data in real time directly from one user to another, all in the browser. ...
New
Cellane
Phoenix 1.6.0 got released last week, with built-in authentication and mailer generators, a whole new HEEx (HTML-aware Embedded Elixir) e...
New
JimmyCarterSon
I am following this tutorial . I have followed carefully correcting errors as I go. The app allows you to create a blog post and add comm...
New
ogoldberg
Any recommendations on good resources for learning Elixir, Phoenix, and Ash?
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
PragmaticBookshelf
Author Spotlight Mike Riley @mriley This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book ...
New