'How can a script check if a particular Docker container is running?

I would like to have a shell script that checks if a particular container is running.

For example, I might want to start the container if it's not already running, or query some piece of information about it like what ports are exposed.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source