geoyws
geoyws

Reputation: 3687

What's the difference between `docker run -d` and `docker run -dit`?

If I would like to use it as a development environment for Node.js, is it alright to just docker run -d?

Do I really need the below?

--interactive , -i      Keep STDIN open even if not attached
--tty , -t              Allocate a pseudo-TTY

Upvotes: 0

Views: 1740

Answers (1)

Adiii
Adiii

Reputation: 59896

In a normal scenario, there is the only one difference

-dit Run the container in the background -it Run the container in the foreground and will allocate a pseudo-terminal.

But what if the entry point is bash? like in the case of ubuntu-dockerfile. As they believe that the user will override the CMD as per their need or dependent Dockerfile.

# overwrite this with 'CMD []' in a dependent Dockerfile
CMD ["/bin/bash"]

So in this case, when you only specify -d your container will be stopped as soon as it started. So what you need to allocate pseudo-terminal by adding -dit.

enter image description here

As you can see that the container is not running, let check-in stoped container.

enter image description here

so we can that container is exited a minutes ago. Let try with -dit enter image description here

We can see that the container is running. Same case with alpine if you run alpine with -d it will also stop.

docker run -d alpine

This will exit as soon as it started, so -dit will Allocate a pseudo-TTY as mentioned in the documentation.

Upvotes: 1

Related Questions