This is the most common thing we come across when playing with docker commands. i.e options -i -t and -d. Are you confident with what does it really mean in docker world. Do you know how does it really work? Let’s learn what is it exactly with a simplest example.
Meaning of the each options
- -i : it means interactive mode
- -t: tty mode
- -d: daemon mode
Let us make an assumption that we have a running docker container called simple_test_container and is a linux machine with ubuntu as base image.
Now lets see what else this command will do when we try to execute a exec command on it.
Scenario 1. Use case of -i
docker exec -i simple_test_container /bin/bash
The use of exec command is to get into the running container. But you will not be able to get into the container because you are in interactive mode. You can just interact with the docker container. The only things you can do here is pass the command that you want to run on the container.
Scenario 2 Use case of -i
Now , run this instead to interact with the container
docker exec -i simple_test_container ls
Now you get the list of items shown as the result. You have successfully interacted with the running container.
Scenario 3 Use case of -t
Suppose we want to get into the container than we use the option -t
docker exec -t simple_test_container bin/bash
The problem, you will face here is though we will successfully get into the running docker container but we will not be able to run any command because we don’t have the -i option enabled that allow us to interact with the container machine.
Scenario 4 Use case of -it
To solve the problem in scenario 3 we would use both option -it which will allow us to get into the running docker container and than interact too.
docker exec -it simple_test_container /bin/bash
The problem, you will face here is once you come out (exit) of the container the container will stop.
Scenario 5 use case of -itd
To solve the issue in scenario 4 we will make use of the -d option which will run the service in daemon mode (background). Now though we come out of the container it will not get halted, will still continue running in background.
Summing up use case of docker -i -t -d options
- -i : to just interact with the docker container
- -d: to run the container in daemon mode (background)
- -t : to run or get into the running container or we call it TTY mode
- -it : allows to get into TTY and interact
- -id: allows interaction only and runs the container in background
- -itd : allows TTY , allows interaction and runs the container in background