How do you open a shell inside a running Docker container?

Docker · Container Management · updated 2026-08-23

docker exec -it [ID] bash — Enter container

Run docker exec -it [ID] bash, replacing [ID] with the container ID or name from docker ps. The -it flags keep the session interactive; use sh instead of bash for minimal images that do not ship bash.

Related Docker shortcuts: Container Management

ShortcutActionNotes
docker run [image]Run containerCreate and start a new container.
docker psList runningList currently running containers.
docker ps -aList allList all containers including stopped.
docker stop [ID]Stop containerStop a running container.
docker rm [ID]Remove containerRemove a stopped container.
docker exec -it [ID] bashEnter containerOpen a bash shell inside a running container.
docker logs [ID]View logsView container logs.
docker restart [ID]RestartRestart a container.

From the Docker reference (24 entries) · all how-to answers