How do you open a shell inside a running Docker container?
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
| Shortcut | Action | Notes |
|---|---|---|
| docker run [image] | Run container | Create and start a new container. |
| docker ps | List running | List currently running containers. |
| docker ps -a | List all | List all containers including stopped. |
| docker stop [ID] | Stop container | Stop a running container. |
| docker rm [ID] | Remove container | Remove a stopped container. |
| docker exec -it [ID] bash | Enter container | Open a bash shell inside a running container. |
| docker logs [ID] | View logs | View container logs. |
| docker restart [ID] | Restart | Restart a container. |
From the Docker reference (24 entries) · all how-to answers