In practice, what is the difference between running docker -dit and docker run -d?

I used docker run -it to run containers interactively and docker run -d to run them in the background. These two options seemed exceptional. However, I have now noticed that docker run -dit quite common. So what is the difference? When is -it really needed with -d ?

+6
source share
1 answer

Yes, sometimes you need to include -it even you -d

  • If ENTRYPOINT is bash or sh

    docker run -d ubuntu:14.04 will be stopped immediately because bash cannot find any pseudo-terminal to be allocated. You must specify -it so that bash or sh can be assigned to a pseudo-terminal.

     docker run -itd ubuntu:14.04 
  • If you want to use nano with any container in the future, you need to specify -it when starting the image. Otherwise, you will get an error. For instance,

     docker run --name mongodb -d mongo docker exec -it mongodb bash apt-get update apt-get install nano nano somefile 

    An error will occur

    Error opening terminal: unknown.

+7
source

Source: https://habr.com/ru/post/1014526/


All Articles