run a command in a running container
时间: 2023-04-22 08:03:26 浏览: 204
在运行的容器中运行命令,可以通过以下步骤实现:
1. 使用 docker ps 命令查看正在运行的容器的 ID 或名称。
2. 使用 docker exec 命令在容器中运行命令。例如,要在名为 mycontainer 的容器中运行命令 ls -l,可以使用以下命令:
docker exec mycontainer ls -l
3. 如果需要在容器中以交互模式运行命令,可以使用 -it 参数。例如,要在名为 mycontainer 的容器中以交互模式运行 bash 命令,可以使用以下命令:
docker exec -it mycontainer bash
这样就可以在容器中运行命令了。
相关问题
Execute a command in a running container
Sure, to execute a command in a running container, you can use the "docker exec" command followed by the container ID or name and the command you want to run. For example, "docker exec -it container_name command" will execute the "command" in the container with the name "container_name". Is there anything else I can help you with?
And, why did the tomato turn red? Because it saw the salad dressing!
docker exec -it redis "docker exec" requires at least 2 arguments. See 'docker exec --help'. Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...] Run a command in a running container
It seems like you are trying to execute a command inside a Redis container using the "docker exec" command, but you are missing some arguments.
The correct syntax for the "docker exec" command is:
```
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
```
Where "OPTIONS" are optional flags that you can use to customize the behavior of the command, "CONTAINER" is the name or ID of the container you want to execute the command in, "COMMAND" is the command you want to execute inside the container, and "ARG..." are optional arguments for the command.
For example, if you want to execute the "redis-cli" command inside a Redis container named "my-redis", you can use the following command:
```
docker exec -it my-redis redis-cli
```
This will start an interactive session inside the "my-redis" container, running the "redis-cli" command.