← 返回命令列表

Linux command

docker-container-exec 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Execute a command in a container

docker container exec [container] [command]

Start an interactive shell in a container

docker container exec -it [container] /bin/bash

Run a command as a specific user

docker container exec -u [user] [container] [command]

Set environment variables and execute a command

docker container exec -e [VAR=value] [container] [command]

Execute a command in a specific working directory

docker container exec -w [/path] [container] [command]

Run a command in the background (detached)

docker container exec -d [container] [command]

Load environment variables from a file

docker container exec --env-file [env.list] [container] [command]

说明

docker container exec runs a new command in a running container. The command runs in the default working directory of the container or the directory specified with --workdir. The command must be an executable; chained or quoted commands do not work. This is the long form of docker exec and behaves identically.

参数

-i, --interactive
Keep STDIN open even if not attached.
-t, --tty
Allocate a pseudo-TTY.
-u, --user _user_
Username or UID (format: user, user:group, uid, uid:gid).
-w, --workdir _dir_
Working directory inside the container.
-e, --env _list_
Set environment variables.
--env-file _file_
Read environment variables from a file.
-d, --detach
Run command in the background.
--detach-keys _string_
Override the key sequence for detaching a container.
--privileged
Give extended privileges to the command.

FAQ

What is the docker-container-exec command used for?

docker container exec runs a new command in a running container. The command runs in the default working directory of the container or the directory specified with --workdir. The command must be an executable; chained or quoted commands do not work. This is the long form of docker exec and behaves identically.

How do I run a basic docker-container-exec example?

Run `docker container exec [container] [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -i, --interactive do in docker-container-exec?

Keep STDIN open even if not attached.