$ docker run --help | grep -e "-i," -e "-t,"
-i, --interactive Keep STDIN open even if not attached
-t, --tty Allocate a pseudo-TTY
· -I keeps standard input (in container) open even if it is not attached · -T assigns a pseudo TTY ??
Overwrite cmd with/bin/bash and start bash. If you add -it, it is inside the container and you can operate it using bash.
$ docker run -it --rm centos:centos8 /bin/bash
[root@fe990f80d393 /]# aa
bash: aa: command not found
[root@fe990f80d393 /]# echo hoge
hoge
[root@fe990f80d393 /]# exit
As soon as the container starts,/bin/bash exits, and --rm deletes the container. If you do without --rm, you can see that the container was not deleted and stopped immediately.
$ docker run --rm centos:centos8 /bin/bash
$
$ docker run centos:centos8 /bin/bash
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7a9cf7a97800 centos:centos8 "/bin/bash" 6 seconds ago Exited (0) 6 seconds ago admiring_goldstine
If you add -t, a pseudo tty will open and you can operate it in the container, but there is no response even if you type a command. exit doesn't work either. I can't close it.
$ docker run --rm -t centos:centos8 /bin/bash
[root@bb3ad19806ed /]# echo hgoe
When I run it, it doesn't seem to return a response. However, when I hit the command, a response is returned and I can exit with exit
$ docker run -i --rm centos:centos8 /bin/bash
echo hoge
hoge
echo hoge
hoge
exit
You can enter it in the standard input of the container by adding -i. When combined with -i and --rm, you can start the container only once and receive only the result.
$ echo "echo hoge" | docker run -i --rm centos:centos8 /bin/bash
hoge
$
With -t you will get a prompt like [root @ bb3ad19806ed /] #
.
If you add -i, a response will be returned when you type the command.
Recommended Posts