Search code examples
dockerdocker-run

Could you clarify when "-it" should be used in a "docker run" command?


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?


Solution

  • 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