1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.