Skip to content

Instantly share code, notes, and snippets.

@gak
Last active January 1, 2016 22:59
Show Gist options
  • Save gak/8214106 to your computer and use it in GitHub Desktop.
Save gak/8214106 to your computer and use it in GitHub Desktop.
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
#!/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)
port = data[0]['NetworkSettings']['Ports']['22/tcp'][0]['HostPort']
cmd = 'ssh root@localhost -p {}'.format(port)
subprocess.call(cmd, shell=True)
127.0.0.1:49251->22/tcp
ssh root@localhost -p 49251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment