karol wołonciej
karol wołonciej

Reputation: 119

running docker container without /bin/bash command

I create docker container with

sudo docker run -it ubuntu /bin/bash

in book The docker book I read

The container only runs for as long as the command we specified, /bin/bash , is running.

didn't I created terminal with option -it and /bin/bash isn't required? will anything change if I don't pass any command in docker run?

Upvotes: 1

Views: 2086

Answers (2)

jkr
jkr

Reputation: 19260

You will get the same behavior if you run

sudo docker run -it ubuntu

because the ubuntu docker image specifies /bin/bash as the default command. You can see that in the ubuntu Dockerfile. As @tadman wrote in their answer, providing a command (like /bin/bash) overrides the default CMD.

In addition, -it does not imply a bash terminal. -t allocates a pseudo-tty, and -i keeps STDIN open even if not attached. See the documentation for further details.

Upvotes: 2

tadman
tadman

Reputation: 211580

That's an override to the default CMD specification. You can run a container with defaults, that's perfectly normal, but /bin/bash is a trick to pop open a shell so you can walk around and check out the built container to see if it's been assembled and configured correctly.

Upvotes: 1

Related Questions