Open a shell inside a running container
Low risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Starts an interactive shell in a running container so you can inspect files and processes from the inside. The container itself keeps running unchanged.
dockerexecshelldebug
Parameters
Name or ID of the running container to enter.
Commands
Confirm the target container is running before attaching
docker ps --filter name=<container>Start an interactive shell inside the container; exit with `exit`
docker exec -it <container> shVerification
docker exec <container> sh -c "echo shell-ok"Prints shell-ok, confirming commands can execute inside the container.
Undo
Not undoable
Opening and exiting the shell changes nothing by itself; any commands you run inside the container have their own effects and are not undone by this recipe.
Pitfalls
- Requires the container to be running; use docker start first if it has exited.
- Minimal images may lack sh; try bash, or the image may have no shell at all (distroless), in which case docker debug or a sidecar container is needed.
- Changes made in the container's writable layer are lost when the container is removed.