Skip to content

docker exec

Description

Runs a command inside a running container, often used to open a shell for debugging.

Syntax

docker exec [OPTIONS] CONTAINER COMMAND

Common Options

Option Description
-it Interactive session with a terminal
-e KEY=VALUE Set an environment variable for the command
-w PATH Set the working directory
-u USER Run as a specific user

Examples

docker exec -it web sh
docker exec web ls /usr/share/nginx/html

Only works on a running container.