-4

When executing this command, I can't just leave out neither i nor t to get the bash to work.

sudo docker exec -it 69e937450dab bash

What does it exactly do? When do I need the command without these parameters?

David
  • 2,926
  • 1
  • 27
  • 61

1 Answers1

0

I will answer it myself:

Normal execution without any flags:

[ec2-user@ip-172-31-109-14 ~]$ sudo docker exec 69e937450dab ls
bin
boot
dev
docker-entrypoint.d
docker-entrypoint.sh
etc

If your command needs an input like cat, you can try:

[ec2-user@ip-172-31-109-14 ~]$ echo test | sudo docker exec 69e937450dab cat

Nothing will show, because there is no input stream going to the docker container. This can be achieved with the -i flag.

[ec2-user@ip-172-31-109-14 ~]$ echo test | sudo docker exec -i 69e937450dab cat
test

Now, let us suppose, you want the bash to start as process:

sudo docker exec 69e937450dab bash

You will see nothing, because the process started in the container. Adding the flag will do the deal:

[ec2-user@ip-172-31-109-14 ~]$ sudo docker exec -t 69e937450dab bash
root@69e937450dab:/# 

But this does not really help, because we need an input stream, which takes our commands and can be received by the bash. Therefore, we need to combine the two:

[ec2-user@ip-172-31-109-14 ~]$ sudo docker exec -i -t 69e937450dab bash
root@69e937450dab:/# ls
bin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  hi  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@69e937450dab:/# 

small recap:

-t for attaching the bash process to our terminal

-i for being able to send inputs via STDIN for example with the keyboard to the bash in the container

Without -i can be used for commands, that don't need inputs. Without -t and bash can be used, when you just want to use one command.

David
  • 2,926
  • 1
  • 27
  • 61