Docker CLI container interaction¶
The Docker Command Line Interface (CLI) provides commands to interact with running containers, facilitating maintenance and debugging by allowing users to execute processes inside an existing container environment.^[600-developer-docker-docker-compose-docker-redis.md]
Executing Commands in Containers¶
To execute commands within a container, the docker exec command is used.^[600-developer-docker-docker-compose-docker-redis.md]
Interactive Sessions¶
The standard syntax for creating an interactive session (where the user can input commands directly) is:
docker exec -it [CONTAINER_ID] [COMMAND]
-i(interactive): Keeps STDIN open even if not attached.-t(tty): Allocates a pseudo-TTY, which is required for shells likebashorsh.[CONTAINER_ID]: The ID or name of the target container.[COMMAND]: The application to run inside the container (e.g.,bash,sh).^[600-developer-docker-docker-compose-docker-redis.md]
Application Example: Redis CLI¶
This interaction pattern is commonly used to access specific client tools within service containers. For example, to access the Redis command-line interface inside a running Redis container, the following command is utilized:^[600-developer-docker-docker-compose-docker-redis.md]
docker exec -it [CONTAINER_ID] redis-cli
This command attaches the user's terminal to the redis-cli tool running inside the Docker container, enabling direct database operations.^[600-developer-docker-docker-compose-docker-redis.md]
Related Concepts¶
- Docker Compose
- [[Redis]]
Sources¶
600-developer-docker-docker-compose-docker-redis.md