What is docker run -it?

$ 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 ??

-it is available

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

-no it

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

-t available

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

-i Yes

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
$ 

Summary

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

What is docker run -it?
What is Docker?
What is Docker
What is Docker
What is Docker? What purpose is it used for?
What is it? ~ 3 types of "no" ~
What is Cubby
What is null? ]
What is java
What is Keycloak
What is maven?
What is Jackson?
What is self
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is programming?
What is Docker? I tried to summarize
Is it OutOfMemoryError?
What is before_action?
What is Byte?
What is Tomcat
What is Maven Assembly?
What is `docker-compose up`?
What is a constructor?
What is vue cli
What is an interface?
What is Ruby's self?
Run Pico with docker
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is Java Encapsulation?
What is permission denied?
What is instance control?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?
What is Guava's @VisibleForTesting?
What is MVC model?
Run Payara with Docker
What is an annotation?
What is Java technology?
What is Java API-java
What is @ (instance variable)?
What is Gradle's Artifact?
What is JPA Auditing?
[Swift] What is dismiss?
[Java] What is flatMap?
What is a Servlet?
What is web development?