I am using the docker-compose.
Some commands like up -d service_name or start service_name are returning right away and this is pretty useful if you don't want the containers running to depend on the state of the shell, like they do with regular up service_name. The one use-case is running it from some kind of continious integration/delivery server.
But this way of running/starting services does not provide any feedback about the actual state of the service afterwards.
The Docker Compose CLI reference for up command does mention the relevant option, but, as for version 1.7.1, it is mutually exclusive with -d:
--abort-on-container-exit Stops all containers if any container was stopped. *Incompatible with -d.*
docker ps -q -f "status=running" --no-trunc | grep $(docker-compose ps -q <service_name>)– Max Oct 20 '18 at 21:58grep ....part ends up with an empty string. – Dzhuneyt Jul 12 '19 at 08:25if [ -z `docker-compose ps -q mysql` ] || [ -z `docker ps -q --no-trunc | grep $(docker-compose ps -q mysql)` ]; then. What this does is: it first checks if the service exists at all (even if it's stopped) and the second part checks if the existing service is actually running. You might want to include this in your example for future readers that glance over the accepted answer only. I think it's useful. – Dzhuneyt Jul 15 '19 at 08:49if [ -z "$( docker ps -q --no-trunc | grep "$( docker-compose ps -q <service_name> )" )" ]. – chawkinsuf May 16 '20 at 20:46