📅  最后修改于: 2023-12-03 15:30:31.613000             🧑  作者: Mango
Docker exec is a command used to run a command inside a container. It is a powerful tool for interacting with running containers and debugging issues.
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
-d
: Detach from the container after running the command-i
: Interactive mode (keep STDIN open even if not attached)-t
: Allocate a pseudo-TTY--user <USERNAME>
: Run the command as a specific user--workdir <DIRECTORY>
: Set the working directory for the command--env <KEY=VALUE>
: Set an environment variableTo run a command inside a container, use the following syntax:
docker exec <CONTAINER_NAME> <COMMAND>
For example, to run the ls
command inside a container, use the following command:
docker exec my_container ls
To run a command as a specific user, use the --user
option:
docker exec --user 1001 my_container ls
To run a command with environment variables, use the --env
option:
docker exec --env MY_VAR=my_value my_container ls
Docker exec is a powerful tool for interacting with running containers. It allows you to run commands inside a container, as well as set environment variables and work in specific directories. By using this command, you can easily debug issues and interact with your containers in real-time.