Skip to content

Instantly share code, notes, and snippets.

@zenatuz
Created December 16, 2019 19:07
Show Gist options
  • Save zenatuz/b1d593f735b4291a3adc9f1f0c7151ae to your computer and use it in GitHub Desktop.
Save zenatuz/b1d593f735b4291a3adc9f1f0c7151ae to your computer and use it in GitHub Desktop.
Docker Containers
import socket
import os
# Porta 81
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('localhost',81))
if result == 0:
print "Port is open"
else:
os.system("docker run -p 81:80 -d dotnetapp:latest")
sock.close()
# Porta 82
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('localhost',82))
if result == 0:
print "Port is open"
else:
os.system("docker run -p 82:80 -d dotnetapp:latest")
sock.close()
# Porta 83
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('localhost',83))
if result == 0:
print "Port is open"
else:
os.system("docker run -p 83:80 -d dotnetapp:latest")
sock.close()
# Porta 84
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('localhost',84))
if result == 0:
print "Port is open"
else:
os.system("docker run -p 84:80 -d dotnetapp:latest")
sock.close()
# Porta 85
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('localhost',85))
if result == 0:
print "Port is open"
else:
os.system("docker run -p 85:80 -d dotnetapp:latest")
sock.close()
* * * * * sleep 5 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 10 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 15 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 20 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 25 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 30 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 35 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 40 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 45 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 50 && python /home/ec2-user/scripts/check_docker.py
* * * * * sleep 55 && python /home/ec2-user/scripts/check_docker.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment