MCPcopy Index your code
hub / github.com/docker/docker-py / build

Method build

docker/api/build.py:12–275  ·  view source on GitHub ↗

Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` needs to be set. ``path`` can be a local path (to a directory containing a Dockerfile) or a remote URL. ``fileobj`` must be a readable file-like object to a Dockerfile. If you have a tar

(self, path=None, tag=None, quiet=False, fileobj=None,
              nocache=False, rm=False, timeout=None,
              custom_context=False, encoding=None, pull=False,
              forcerm=False, dockerfile=None, container_limits=None,
              decode=False, buildargs=None, gzip=False, shmsize=None,
              labels=None, cache_from=None, target=None, network_mode=None,
              squash=None, extra_hosts=None, platform=None, isolation=None,
              use_config_proxy=True)

Source from the content-addressed store, hash-verified

10
11class BuildApiMixin:
12 def build(self, path=None, tag=None, quiet=False, fileobj=None,
13 nocache=False, rm=False, timeout=None,
14 custom_context=False, encoding=None, pull=False,
15 forcerm=False, dockerfile=None, container_limits=None,
16 decode=False, buildargs=None, gzip=False, shmsize=None,
17 labels=None, cache_from=None, target=None, network_mode=None,
18 squash=None, extra_hosts=None, platform=None, isolation=None,
19 use_config_proxy=True):
20 """
21 Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
22 needs to be set. ``path`` can be a local path (to a directory
23 containing a Dockerfile) or a remote URL. ``fileobj`` must be a
24 readable file-like object to a Dockerfile.
25
26 If you have a tar file for the Docker build context (including a
27 Dockerfile) already, pass a readable file-like object to ``fileobj``
28 and also pass ``custom_context=True``. If the stream is compressed
29 also, set ``encoding`` to the correct value (e.g ``gzip``).
30
31 Example:
32 >>> from io import BytesIO
33 >>> from docker import APIClient
34 >>> dockerfile = '''
35 ... # Shared Volume
36 ... FROM busybox:buildroot-2014.02
37 ... VOLUME /data
38 ... CMD ["/bin/sh"]
39 ... '''
40 >>> f = BytesIO(dockerfile.encode('utf-8'))
41 >>> cli = APIClient(base_url='tcp://127.0.0.1:2375')
42 >>> response = [line for line in cli.build(
43 ... fileobj=f, rm=True, tag='yourname/volume'
44 ... )]
45 >>> response
46 ['{"stream":" ---\\u003e a9eb17255234\\n"}',
47 '{"stream":"Step 1 : VOLUME /data\\n"}',
48 '{"stream":" ---\\u003e Running in abdc1e6896c6\\n"}',
49 '{"stream":" ---\\u003e 713bca62012e\\n"}',
50 '{"stream":"Removing intermediate container abdc1e6896c6\\n"}',
51 '{"stream":"Step 2 : CMD [\\"/bin/sh\\"]\\n"}',
52 '{"stream":" ---\\u003e Running in dba30f2a1a7e\\n"}',
53 '{"stream":" ---\\u003e 032b8b2855fc\\n"}',
54 '{"stream":"Removing intermediate container dba30f2a1a7e\\n"}',
55 '{"stream":"Successfully built 032b8b2855fc\\n"}']
56
57 Args:
58 path (str): Path to the directory containing the Dockerfile
59 fileobj: A file object to use as the Dockerfile. (Or a file-like
60 object)
61 tag (str): A tag to add to the final image
62 quiet (bool): Whether to return the status
63 nocache (bool): Don't use the cache when set to ``True``
64 rm (bool): Remove intermediate containers. The ``docker build``
65 command now defaults to ``--rm=true``, but we have kept the old
66 default of `False` to preserve backward compatibility
67 timeout (int): HTTP timeout
68 custom_context (bool): Optional if using ``fileobj``
69 encoding (str): The encoding for a stream. Set to ``gzip`` for

Calls 9

_set_auth_headersMethod · 0.95
process_dockerfileFunction · 0.85
joinMethod · 0.80
_urlMethod · 0.80
get_environmentMethod · 0.80
_postMethod · 0.80
_stream_helperMethod · 0.80
updateMethod · 0.45
closeMethod · 0.45