Compare

Docker Run vs Exec

A practical explanation of the difference between starting a container and running a command inside one.

`docker run` starts a new container. `docker exec` runs a command inside an existing container. They sound similar, but they operate on different lifecycles.

Use Run When

You need to create and start a new container from an image.

You want to define ports, env vars, volumes, or startup behavior.

Use Exec When

The container is already running and you need to inspect or debug it.

You want a shell or a one-off command inside the running process context.

Rule of Thumb

Run creates. Exec enters.

Want the short version? Browse the compact sheet views and save the commands you use most into a Cheatbook.