Interview Prep/Docker/Networking and Compose

Run a one-off migration job with Compose without keeping the container.

BeginnerScenarioNetworking and Compose
Answer

Situation read → Need to run a command once in the service context.

What I'd do →

docker compose run --rm api python manage.py migrate

Use profiles: ["tools"] so it does not start with up.

Why → run creates a new container using the service config, --rm removes it afterwards, while exec attaches to a running one.

Interview tip → Use exec for running containers, run for fresh ones.

All Docker questions Roadmap: Docker & containers

More on Networking and Compose