-
-
Save batandwa/10577970 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
e53a722096f0 aafd21071b99 /opt/bin/run_all 41 minutes ago Up 28 minutes 127.0.0.1:49251->22/tcp, 127.0.0.1:49252->9200/tcp es-b | |
0208431f9c7b aafd21071b99 /opt/bin/run_all 41 minutes ago Up 28 minutes 127.0.0.1:49249->22/tcp, 127.0.0.1:49250->9200/tcp es-a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import subprocess | |
import json | |
cmd = 'sudo docker inspect {}'.format(sys.argv[1]) | |
output = subprocess.check_output(cmd, shell=True).decode('utf-8') | |
data = json.loads(output) | |
if data[0]['NetworkSettings']['Ports']['22/tcp'] != None: | |
port = data[0]['NetworkSettings']['Ports']['22/tcp'][0]['HostPort'] | |
else: | |
port = 22 | |
if data[0]['NetworkSettings']['IPAddress'] != None: | |
host = data[0]['NetworkSettings']['IPAddress'] | |
else: | |
host = 'localhost' | |
cmd = 'ssh -A -p {} root@'.format(port)+host | |
subprocess.call(cmd, shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127.0.0.1:49251->22/tcp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh root@localhost -p 49251 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment