2

I found that -

By default, when no option is provided to the docker run command, the root process is started in the foreground. This means that the standard input, output, and error from the root process are attached to the terminal session.

So, what is the difference between $ docker container run -ait ubuntu & $ docker container run -it ubuntu?

When to use --attach with docker container run?

Ahmad Ismail
  • 11,636
  • 6
  • 52
  • 87
  • Did you read the description in https://docs.docker.com/engine/reference/commandline/run/? What difference have you observed in use? – jonrsharpe Jan 19 '20 at 14:32
  • I read https://docs.docker.com/engine/reference/commandline/container_run/ and also the difference between attach and exec. https://stackoverflow.com/questions/30960686/difference-between-docker-attach-and-docker-exec but could not understand in this context. – Ahmad Ismail Jan 19 '20 at 14:34

1 Answers1

2

If you do not specify -a then Docker will attach to both stdout and stderr when running in foreground mode. You can use --attach option to attach to specific streams instead.

-a=[]           : Attach to `STDIN`, `STDOUT` and/or `STDERR`
docker run -a stdin -a stdout -i -t ubuntu /bin/bash
Shashank V
  • 10,007
  • 2
  • 25
  • 41