✦ For everyone, free.

Practical knowledge for real and everyday life

Home

9.4.4.2 Exec Shell Access

A focused guide to Exec Shell Access, connecting core concepts with practical Docker and container operations.

Exec shell access uses docker compose exec to open an interactive shell session directly inside a running service's container, providing a familiar, exploratory way to inspect and interact with that container's filesystem and environment in real time.

Opening an Interactive Shell

Running a shell as the command opens an interactive session within the container.

docker compose exec api sh
docker compose exec api bash

Which shell is available depends on what's actually installed in that particular image — a minimal Alpine-based image typically only has sh, while a more full-featured image might include bash as well.

Exploring the Container's Filesystem Interactively

Once inside, ordinary shell commands explore the container's environment exactly as they would on any other system.

ls -la /app
cat /app/package.json
ps aux
env
Why Interactive Shell Access Is Useful for Exploratory Investigation

When the exact command needed to investigate something isn't yet known, an interactive shell allows exploring freely — trying different commands, navigating the filesystem, checking various aspects of the environment — without needing to predict in advance exactly what to run.

docker compose exec api sh
$ find / -name "*.log" 2>/dev/null
$ cat /var/log/app/error.log
Exiting the Shell Session

Exiting the shell ends the exec session, returning to the host's own shell, without affecting the container's continued running.

exit

The api service continues running normally after this interactive session ends.

Why Exec Shell Access Matters

Interactive shell access is one of the most directly useful capabilities exec provides, offering a familiar, flexible way to explore and investigate a running container's actual state when the exact diagnostic command needed isn't yet clear.