Ad space (banner)
AD

Got the fundamentals? A structured Docker course is a fast way to level up.

Find Docker courses on Udemy

Affiliate link. Costs you nothing extra.

🐳Docker Lessons
Lesson 20 / 45

Running Commands Inside a Container with docker exec

When you want to look around inside a running container, use docker exec. It runs a command in a container that is already running.

The syntax is docker exec -it container command. The -it flags give you an interactive terminal.

Running docker exec -it web bash opens a shell inside the web container, letting you inspect files and processes as if you were logged into it.

A common stumble is expecting changes made this way to persist. Edits inside a running container vanish when it is removed — real changes belong in the Dockerfile.

In real work, it is the standard way to debug: check config files, run a database client, see what the container actually sees.

Docker
Try it (type this into the pseudo terminal)
docker exec -it web bash

🧑‍💻 You can type this command into the Docker pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)