Reputation: 10204
If I use
docker run myimage /bin/bash -c "pwd"
or
docker run -it myimage /bin/bash -c "pwd"
the results are the same. Then, what is the sense of "-it"? I learned that "-i" is for interactive, "-t" is for tty. But those are abstract nouns for me. Could you clarify when "-it" should be used in a "docker run" command?
Upvotes: 0
Views: 364
Reputation: 681
You can use -it
flag when you want interact with container.
For example:
$ docker run -it myimage /bin/bash
this will give you a shell inside container and keep you connected to bash
/ #
And this will run any command but close the connection and drop you to your host machine's shell
$ docker run myimage /bin/bash -c "pwd"
/
test@host $
So you would use -it
to connect and execute more commands inside container.
and finally exit out of container
/ # exit
exited
Upvotes: 1
Reputation: 1768
Mentioning the docs,
For interactive processes (like a shell), you must use -i -t together in order to allocate a tty for the container process.
Essentially what that does is adding a terminal driver which allows you to interact with your container as a terminal session.
After running your container, you can run docker ps
to get the hash id of your container which you can then access by running:
docker exec -it containeridhash sh
Upvotes: 1