Reputation: 1454
Why when i run the command
docker run ubuntu
without option '-it' is not possible to interact with the created container even when running command start with the -a -i options
docker start -a -i CONTAINER_ID
or when i run
docker start CONTAINER_ID
simply the container has the status "Exit (0) 4 seconds ago"
But when i run
docker run -it ubuntu
i can use bash shell of ubuntu using 'docker start -a -i'
Upvotes: 0
Views: 7583
Reputation: 1184
When you run docker run
without -it
it's still running the container but you've not given it a command, so it finishes and exits.
If you try:
docker run ubuntu /bin/bash -c "echo 'hello'";
It'll run ubunu, then the command, and then finish because there is no reason for it to be kept alive afterwards.
-i
is saying keep it alive and work within in the terminal (allow it to be interactive), but if you type exit
, you're done and the container stops.
-t
is showing the terminal of within the docker container (see: What are pseudo terminals (pty/tty)?)
-it
allows you to see the terminal in the docker instance and interact with it.
Additionally you can use -d
to run it in the background and then get to it afterwards.
Ex:
docker run -it -d --name mydocker ubuntu;
docker exec -it mydocker /bin/bash;
Upvotes: 7
Reputation: 9886
TLDR is -it
allows you connect a terminal to interactively connect to the container.
If you run docker run --help
, you can find the details about docker run
options.
$ docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container
Options:
...
-i, --interactive Keep STDIN open even if not attached
...
-t, --tty Allocate a pseudo-TTY
Upvotes: 1