What does docker exec mean?

WBOY
Release: 2022-07-08 15:50:07
Original
5315 people have browsed it

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...]".

What does docker exec mean?

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

What does docker exec mean

docker exec: Execute commands in a running container

Syntax

docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Copy after login

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/
Copy after login

In the container mynginx Open an interactive mode terminal:

runoob@runoob:~$ docker exec -i -t  mynginx /bin/bash
root@b1a0703e41e7:/#
Copy after login

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…" 
...
Copy after login

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
Copy after login

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

What does docker exec mean?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template