Practically, what is the difference between docker run -dit(-itd) vs docker run -d?

后端 未结 1 1599
旧时难觅i
旧时难觅i 2021-02-01 15:49

I\'ve used docker run -it to launch containers interactively and docker run -d to start them in background. These two options seemed exclusive. However

相关标签:
1条回答
  • 2021-02-01 16:40

    Yes, sometimes, it's necessary to include -it even you -d

    1. When the ENTRYPOINT is bash or sh

      docker run -d ubuntu:14.04 will immediately stop, cause bash can't find any pseudo terminal to be allocated. You have to specify -it so that bash or sh can be allocated to a pseudo terminal.

       docker run -dit ubuntu:14.04
      
    2. If you want to use nano or vim with any container in the future, you have to specify -it when the image starts. Otherwise you'll get error. For example,

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

      It will throw an error

      Error opening terminal: unknown.

    0 讨论(0)
提交回复
热议问题