Docker Exec command

Docker Exec command #

Syntax #

docker exec <options> <container> <command>

Start a bash terminal within a container #

docker exec -it <container> /bin/bash

Start a container as the root user #

docker exec -u 0 -it <container> /bin/bash

Execute a command #

docker exec <container> <command>

Execute multiple commands #

docker exec <container> bash -c "command1 ; command2 ; command3"

Executing a command in a specific directory #

docker exec -w /path/to/directory <container> <command>

Executing a command with environment variables #

docker exec -e var='value' <container> <command>