Last active
December 31, 2015 21:29
-
-
Save KushalP/8047188 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
""" | |
Harbour. | |
Usage: | |
harbour [ID] env | |
harbour [ID] ports | |
harbour (-h | --help) | |
Arguments: | |
ID The id of the container we want to work on. | |
Options: | |
-h --help Show this screen | |
""" | |
from __future__ import print_function | |
from docker import Client | |
from docopt import docopt | |
if __name__ == "__main__": | |
args = docopt(__doc__) | |
client = Client(version="1.6") | |
container = client.inspect_container(args["ID"]) | |
if args["env"] is True: | |
print(*container["Config"]["Env"], sep="\n") | |
if args["ports"] is True: | |
ip = container["NetworkSettings"]["IPAddress"] | |
raw_ports = container["NetworkSettings"]["Ports"].keys() | |
ports = [port.split("/")[0] for port in raw_ports] | |
addresses = ["{ip}:{port}".format(ip=ip, port=port) for port in ports] | |
print(*addresses, sep="\n") |
This file contains hidden or 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
docker-py==0.2.3 | |
docopt==0.6.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment