Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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, now I've noticed that docker run -dit (or docker run -itd) is quite common. So what is the difference? When -it is really needed together with -d?

like image 839
vehsakul Avatar asked Jan 29 '17 00:01

vehsakul


People also ask

What is the difference between Docker run and Docker exec?

Docker Run vs Docker Exec! This is a fairly common question – but has a simple answer! In short, docker run is the command you use to create a new container from an image, whilst docker exec lets you run commands on an already running container! Easy!

What is the difference between Docker run and Docker build?

docker build builds a new image from the source code. docker create creates a writeable container from the image and prepares it for running. docker run creates the container (same as docker create ) and runs it.

What is the difference between Docker run and Docker CMD?

RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. CMD is the command the container executes by default when you launch the built image.

What is the difference between Docker run CMD and ENTRYPOINT?

The ENTRYPOINT instruction looks almost similar to the CMD instruction. However, the main highlighting difference between them is that it will not ignore any of the parameters that you have specified in the Docker run command (CLI parameters).


1 Answers

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.

like image 196
Rafaf Tahsin Avatar answered Oct 08 '22 18:10

Rafaf Tahsin