Blog › Docker · Published 2026-11-26

How to open a shell inside a running Docker container

To get a console inside a container that is already running, use docker exec with the interactive and TTY flags:

docker exec -it my-container bash

Many minimal images (for example Alpine-based ones) do not include bash. Use sh instead:

docker exec -it my-container sh

Find the container name

docker ps

Start a new container with a shell

docker run -it ubuntu bash

-i keeps standard input open and -t allocates a terminal. Exiting the shell started with docker exec does not stop the container. Exiting the main process started with docker run does.

Official sources

Need help with your project?
We build websites, systems and automation. Start your project WhatsApp

All articles