Confused about Docker -t option to Allocate a pseudo-TTY

What exactly does this option do? I’ve been reading a lot on TTY and am still confused. I played around with not having the -t and just -i and it seems like programs that expect user input throw an error without the -t. Why is it important for pseudo-TTY to be enabled?

  • java web app and Postgres on websphere-liberty
  • Docker Volumes: Docker Volume does not get mounted correctly on Amazon Linux
  • Connect shipyard with existing docker images?
  • How to run docker image as a non-root user?
  • Docker swarm use local service instance
  • Docker's healthcheck on Windows container and exit code (“||” linux equivalent)
  • org.jolokia:docker-maven-plugin:0.10.4:push (code: 500, Internal Server Error)
  • Starting Docker containers from PHP
  • MongoDB in Docker - backup database on container shutdown
  • Using a Makefile to get latest git tag
  • How to read environment variable in Nodejs?
  • Liberty Docker Image is not running
  • 3 Solutions collect form web for “Confused about Docker -t option to Allocate a pseudo-TTY”

    The “-t” argument is NOT documented well, or mentioned by many people often, according to a Google search.

    It doesn’t even show up when you display a list of (what should be) all docker client arguments by typing “docker” at the Bash prompt (with the latest version of 1.8.1).

    In fact, if you try to get specific help about this argument by typing “docker -t –help” if gives this amazingly vague reply:

    “flag provided but not defined: -t”

    So, you can’t be blamed for being confused about this argument!

    There is a mention in the Docker online documention which says it is to “Allocate a pseudo-tty” and is often used with -i:

    I saw it used in the documentation for the terrific jwilder/nginx-proxy docker container in the following way:

    docker run -d -p 80:80 –name nginx -v /tmp/nginx:/etc/nginx/conf.d -t nginx

    In this case, what it does is send the output to the ‘virtual’ tty (Bash command prompt/terminal) within this docker container. You can then see this output by running the docker command “docker logs CONTAINER” where CONTAINER is the first couple of characters of this container’s ID. This CONTAINER ID can be found by typing “docker ps -a”

    I’ve seen this “-t” argument mentioned briefly in the following link, where it says, “The -t and -i flags allocate a pseudo-tty and keep stdin open even if not attached. This will allow you to use the container like a traditional VM as long as the bash prompt is running.”

    I hope this helps! I’m not sure why this isn’t documented or used much. Maybe it’s experimental and will be implemented as a documented feature in upcoming versions.

    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.

    What I know about the -t is the following:

    docker exec -ti CONTAINER bash – allows me to “login” in the container. It feels like ssh-ing (it’s not).

    But the trouble was when I wanted to restore a database.

    Usually I dodocker exec -ti mysql.5.7 mysql – Here I execute the mysql command in the container and get an interactive terminal.

    I added <dump.sql to the previous command so I can restore a db. But it failed with cannot enable tty mode on non tty input.

    Removing the -t helped. Still don’t understand why:

    docker exec -i mysql.5.7 mysql < dump.sql

    The last one works. Hope this helps people.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.