Grepping the output of systemctl status to see whether a service runs breaks easily. There is a command made for scripts.
Use the exit code:
if systemctl is-active --quiet docker.service; then
echo "docker is running"
else
echo "docker is not running"
fi
The man page says is-active checks whether the specified units are active, meaning running, and returns exit code 0 if at least one is active, non-zero otherwise. Unless --quiet is given it also prints the current state to standard output. With the flag your script only sees the exit code.
Without --quiet you get a word such as active, inactive or failed, which suits a quick look at the terminal:
systemctl is-active docker.service
Watch the wording “at least one”. When you pass several units, a single active one makes the whole command succeed, so check units one at a time when all of them have to be up. The exit code also works in a chain, for example systemctl is-active --quiet docker.service && docker ps.
Active also says nothing about the next boot. Whether a unit starts at boot is a separate question, answered by systemctl is-enabled. A unit can be active now and disabled, or enabled and currently stopped, so a script that cares about both needs both checks.
Further reading: systemd: systemctl man page