1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

チラシの裏: PythonでDockerを使う

Last updated at Posted at 2014-01-30

> sudo pip install docker-py
..
> python
>>> import docker
>>> c = docker.Client(base_url='unix://var/run/docker.sock', version='1.8', timeout=10)
>>> c.info()
{u'KernelVersion': u'3.2.0-4-amd64', u'NFd': 10, u'MemoryLimit': 0, u'InitSha1': u'', u'SwapLimit': 0, u'Driver': u'aufs', u'IndexServerAddress': u'https://index.docker.io/v1/', u'NGoroutines': 15, u'Images': 109, u'InitPath': u'/usr/local/bin/docker', u'Containers': 11, u'LXCVersion': u'0.8.0-rc1', u'Debug': 0, u'NEventsListener': 221, u'DriverStatus': [[u'Root Dir', u'/var/lib/docker/aufs'], [u'Dirs', u'135']], u'IPv4Forwarding': 1}
>>> help(c.containers)
Help on method containers in module docker.client:

containers(self, quiet=False, all=False, trunc=True, latest=False, since=None, before=None, limit=-1) method of docker.client.Client instance

(注意: 上の場所はLESSで表示されたり環境によって表示され方変わる)
>>> c.containers(all=True)
[{u'Command': u'do not look at me',
  u'Created': 1391059918,
  u'Id': u'97115535aacbba9fcf19bbd9bc8ca9aac66132f79acf2820d6225a554b06191d',
  u'Image': u'griflet:oajxuu024euvttj0ar0s-23b235cf82b0301f864f6ad100a2b3245b7dca7d',
  u'Names': [u'/drunk_heisenberg'],
  u'Ports': None,
  u'SizeRootFs': 0,
  u'SizeRw': 0,
  u'Status': u'Exit 0'},
 {u'Command': u'do not look at me',
  u'Created': 1391059896,
  u'Id': u'5c796656a414673ead3c74aaafd95ae6f80c00125eda8cf01ea826b76eca7586',
  u'Image': u'54055ba1f6fe',
  u'Names': [u'/pensive_galileo'],
  u'Ports': None,
  u'SizeRootFs': 0,
  u'SizeRw': 0,
  u'Status': u'Exit 0'},
 {u'Command': u'do NOT look at me :-)',
..

(docker ps です基本的に)

ipythonだと"c."の後でTabぶち込むと候補が出てくるので、中途半端なシェル環境より分かりやすい操作になるかもしれません。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?