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.
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate