Home >Operation and Maintenance >Docker >What does docker exec mean?
In docker, exec is a command, which means to execute a command in a running container; using this command can execute the command in the container in the same way as on the host. When the parameter is set to When "-d" is used, it means running in the background, and the syntax is "docker exec [OPTIONS] CONTAINER COMMAND [ARG...]".
The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.
docker exec: Execute commands in a running container
Syntax
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
OPTIONS Description:
-d: Detached mode: Run in the background
-i: Keep STDIN open even if not attached
-t: Allocate a pseudo terminal
What exec actually wants to express It executes commands in a running container. By using the exec command, commands can be executed in the container the same as on the host.
The example is as follows:
Execute the /root/runoob.sh script in the container in interactive mode in the container mynginx:
runoob@runoob:~$ docker exec -it mynginx /bin/sh /root/runoob.sh http://www.runoob.com/
In the container mynginx Open an interactive mode terminal:
runoob@runoob:~$ docker exec -i -t mynginx /bin/bash root@b1a0703e41e7:/#
You can also use the docker ps -a command to view the running containers, and then use the container ID to enter the container.
# docker ps -a ... 9df70f9a0714 openjdk "/usercode/script.sh…" ...
9df70f9a0714 in the first column is the container ID.
Execute bash on the specified container through the exec command:
# docker exec -it 9df70f9a0714 /bin/bash
What exec actually means is to execute the command in a running container. (Go into the container and take a look)
docker exec -it container/bin/bash This command line actually executes /bin/bash in -it mode
Recommended learning: "docker video tutorial"
The above is the detailed content of What does docker exec mean?. For more information, please follow other related articles on the PHP Chinese website!