The docker exec command is used to run a command in a running Docker container. It allows you to execute commands inside the container's environment, which is useful for debugging, maintenance, or interacting with the application running inside the container.
The basic syntax is:
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
CONTAINER: The name or ID of the running container where you want to execute the command.COMMAND: The command you want to run inside the container.[ARG...]: Any additional arguments for the command.
Common options include:
-i(or--interactive): Keep STDIN open even if not attached.-t(or--tty): Allocate a pseudo-TTY, providing a terminal interface.
For example, to start an interactive shell session inside a container named my_container, you would use:
docker exec -it my_container /bin/bash
This command opens a bash shell inside the specified container, allowing you to run commands as if you were directly interacting with the container's terminal.
