If you run a test or a one-off job with Compose, you want your shell to know whether it passed. --exit-code-from turns a service’s exit code into the exit code of the whole command.
The reference says the option returns the exit code of the selected service container and implies --abort-on-container-exit. That second part means Compose stops all the other containers as soon as any one stops, which is what you want when a database should go away after the test is done.
docker compose up --exit-code-from tests --build
echo $?
Here tests is a service in the file that runs a test suite against the other services, maybe a database and an app. When the tests finish, Compose stops the rest and exits with the code of tests, so 0 means green and anything else means red. In a script or a CI job you can put it behind an if and clean up with docker compose down afterwards.
There is a sibling option, --abort-on-container-failure, which stops everything only when a container exits with a failure.
Both options are incompatible with -d, so you cannot detach, and the output of every service streams to your terminal. I would not use it for a normal long-running stack, since the first container that exits, for whatever reason, takes the rest down with it.
Further reading: docker compose up