3

I ran this command:

docker run -d -ti foo

it works, but I realized that I probably forgot to remote the -ti part. I assume that docker ignores those flags if -d is used, does anyone know? It seems like -ti and -d would contradict each other?

2 Answers2

1

It still sets up the input filehandle, and allocates a pseudo tty for the container. If the app inside the container attempts to read from stdin, it will hang waiting on input rather than exit immediately or fail. Later on, you can attach to that process. E.g.

$ docker run -dit --name test-dit busybox sh
f0e057ce47e03eb227aacb42e3a358b14fa5d8b26ad490fcec7cbfe0cd3cce73

$ docker run -d --name test-d busybox sh
4f2583d3380953f328b702c88884fbe55f16c44bce13dbccc00c4bb81f3270f2

$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                      NAMES 
4f2583d33809        busybox             "sh"                     5 seconds ago       Exited (0) 4 seconds ago                              test-d 
f0e057ce47e0        busybox             "sh"                     14 seconds ago      Up 13 seconds                                         test-dit 

$ docker container attach test-dit
/ #
/ # ls
bin   dev   etc   home  proc  root  sys   tmp   usr   var
/ # exit

$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                      NAMES   
4f2583d33809        busybox             "sh"                     22 seconds ago      Exited (0) 21 seconds ago                              test-d  
f0e057ce47e0        busybox             "sh"                     31 seconds ago      Exited (0) 2 seconds ago                               test-dit

In the first container ls command, you can see the shell without the -it option immediately exited, while the one with -it was available to connect and run commands.

BMitch
  • 231,797
  • 42
  • 475
  • 450
0

It does not ignore -ti.

The -ti part means it enables direct user interaction, and the -d part means it detaches the container the moment it gets started. So, in order to actually interact with it, you'll have to do

?> docker attach foo

So, yes, it might not be very useful, but it neither causes an impossible situation, nor one you cannot get out of.

jogojapan
  • 68,383
  • 11
  • 101
  • 131