xxxxxxxxxx
# check if Docker is running or not
sudo service docker status
# or
service docker status
# how to run Docker?
sudo service docker start
# or
service docker start
# how to stop Docker?
sudo service docker stop
# or
service docker start
xxxxxxxxxx
import subprocess
def is_docker_running():
try:
# Execute 'docker info' command and capture the output
output = subprocess.check_output(['docker', 'info']).decode('utf-8').strip()
# Check if the output contains 'Server Version'
if 'Server Version' in output:
return True
except subprocess.CalledProcessError:
pass
return False
# Check if Docker is running
if is_docker_running():
print("Docker is running!")
else:
print("Docker is not running!")