Docker命令-exec

命令

docker exec

描述

Run a command in a running container
在正在运行的容器中运行命令

用法

1
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

选项

1
2
3
4
5
6
7
8
9
10
Options:
--detach , -d Detached mode: run command in the background
--detach-keys Override the key sequence for detaching a container
--env , -e Set environment variables
--env-file Read in a file of environment variables
--interactive , -i Keep STDIN open even if not attached
--privileged Give extended privileges to the command
--tty , -t Allocate a pseudo-TTY
--user , -u Username or UID (format: <name|uid>[:<group|gid>])
--workdir , -w Working directory inside the container

注意

示例

1
2
3
4
5
6
$ docker run --name ubuntu_bash --rm -it ubuntu bash
$ docker exec -d ubuntu_bash touch /tmp/file
$ docker exec -it ubuntu_bash bash
$ docker exec -it -e VAR=1 ubuntu_bash bash
$ docker exec -it ubuntu_bash pwd
$ docker exec -it -w /root ubuntu_bash pwd