Hi!
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?
Share and learn in the Docker community.
Hi!
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: https://docs.docker.com/engine/reference/run/
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;
EOF
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.
Thanks for your answer! In what cases it may need to specify -t
?
Please have a look at this: Docker run reference | Docker Docs
I read it, but it didn’t add much clarity for me
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.