Enter container

2 snippets in Docker

DKDocker

Execute a Command in a Running Container

DK · Containers
syntax
docker exec [options] <container> <command>
example
docker exec -it web-api sh
docker exec web-api cat /app/config.json
docker exec -u root web-api apt-get update
output
/ #

Note The container must be running. Use -it for an interactive shell. The -u flag lets you override the user (e.g., run as root even if the image uses a non-root user).

Open a Debug Shell

DK · Debugging
syntax
docker exec -it <container> <shell>
example
docker exec -it web-api sh
docker exec -it db-postgres bash
docker exec -it web-api sh -c 'ls -la /app && cat /app/.env'
output
/app #

Note Alpine-based images have sh but not bash. If the container has no shell at all (distroless or scratch), you can use docker debug (Docker Desktop) or copy a static busybox binary in via docker cp.