Created
June 2, 2017 09:34
-
-
Save quentinsf/5c93b564743c154e831cb57d6c8e95c6 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Quick experiment with Python 'docker' module" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import docker\n", | |
"client = docker.from_env()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Container 'docker_codaweb_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 80/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.8 codaweb 220d0af19889\n", | |
"\n", | |
"Container 'docker_celery_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 80/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.9 celery 6d242ff9148c\n", | |
"\n", | |
"Container 'docker_nginx-notify_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 443/tcp\n", | |
" 80/tcp\n", | |
" 8021/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.7 15498c2e5cee nginx-notify\n", | |
"\n", | |
"Container 'docker_notifications_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 8022/tcp\n", | |
" 8021/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.6 23a211c8ee0a notifications\n", | |
"\n", | |
"Container 'docker_content_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 80/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.4 content 164fe381f961\n", | |
"\n", | |
"Container 'docker_codadb_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 3306/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.3 codadb bea3eca88b5f\n", | |
"\n", | |
"Container 'docker_rabbitmq_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 4369/tcp\n", | |
" 25672/tcp\n", | |
" 5672/tcp\n", | |
" 5671/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.5 42f622e370f5 rabbitmq\n", | |
"\n", | |
"Container 'docker_memcache_1'\n", | |
"\n", | |
" Exposed Ports:\n", | |
" 11211/tcp\n", | |
"\n", | |
" IP addresses and DNS aliases\n", | |
" 172.21.0.2 965db399f906 memcache\n" | |
] | |
} | |
], | |
"source": [ | |
"for c in client.containers.list():\n", | |
" print(\"\\nContainer '{}'\".format(c.name))\n", | |
" \n", | |
" print(\"\\n Exposed Ports:\")\n", | |
" for port, info in c.attrs['Config']['ExposedPorts'].items():\n", | |
" print(\" {}\".format(port))\n", | |
" \n", | |
" print(\"\\n IP addresses and DNS aliases\")\n", | |
" for name, net in c.attrs['NetworkSettings']['Networks'].items():\n", | |
" print(\" {} {}\".format(net['IPAddress'], \" \".join(net['Aliases'])))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment