Docker Community Forums

Share and learn in the Docker community.

When make sense to use -i, -t keys separately?


I use keys -it when I want to connect to the terminal inside the launched container. I tried using separately -i and -t keys, but I don’t understand what are they doing if they used not in couple.

Can someone help deal with this?

I asked a stupid question, or are these some unused parameters that no one knows about?

Afaik there’s no difference if you type those switches separately or clocked togeter as these don’t take any arguments.
Please have a look at this:
Scroll down to the “Foreground” paragarph.

if you want to work interactivly in the terminal of the container, both should be used togeter.

Though, if you intend to run a container that does interaction with something you pipe into the container, using STDIN, the (-t) termainal flag would break that operation.

You can do something like this, where you pass something via STDIN into the container, which uses it as input for interactive processing.

docker run -i --rm -e PGPASSWORD=yourpass  postgres psql -h some-postgres -U postgres << EOF
create database some-database;
create database some-other-database;

The command above allows to script the psql command in a postgres container to create two databases:
postgres is the container name
psql is the command
-h some-postgres -U postgres are the params
– << pipes the here-doc between both EOF blocks into STDIN of the active process in the container.

This will not work with -t.

1 Like

Thanks for your answer! In what cases it may need to specify -t?

Please have a look at this:

I read it, but it didn’t add much clarity for me :roll_eyes:

You use -t if you want direct user interaction on the terminal:

docker run -it --rm -e PGPASSWORD=yourpass  postgres psql -h some-postgres -U postgres

This will open psql in the container and allow to interactivly work on the terminal inside the container, pretty much like if psql would run localy on your host.

Not sure if -t without -i even makes sense. Though -i without -t definitly has its use.

1 Like