1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
from . import builds
from . import containers
from . import images
_client = None
def init(client):
"""
Set a client object to be used by the efficiency module.
**Params:**
client: a `docker.Client` object that will be used globally by the
module
"""
global _client
_client = client
def copy_to_fs(container, path, target='.'):
"""
Copy file from container to filesystem
**Params:**
container_id: ID of the container to copy from
path: path to the file in the container
target: folder where file will be copied (default ".")
"""
return containers.copy_to_fs(
_client, container, path, target
)
def start_auto_remove(container, *args, **kwargs):
"""
Start a container and try to remove it when it's finished running,
similar to using --autorm in the docker CLI.
**Params:**
container: ID of the container to be started
args, kwargs: `Client.start()` arguments
"""
return containers.start_auto_remove(
_client, container
)
def pull(repo, tag=None, insecure_registry=False, auth_config=None):
"""
Pull an image and stream the response chunks as JSON objects.
If an error is encountered during streaming, a DockerException will be
raised.
**Params:**
repo: Name of the repository to pull
tag: Optional tag name to pull (default: latest)
insecure_registry: Set to true if pulling from an insecure registry
auth_config: Optional transient auth config object
"""
return images.pull(
_client, repo, tag, insecure_registry, auth_config
)
def push(repo, tag=None, insecure_registry=False):
"""
Push an image and stream the response chunks as JSON objects.
If an error is encountered during streaming, a DockerException will be
raised.
**Params:**
repo: Name of the repository to push
tag: Optional tag name to push (default: all)
insecure_registry: Set to true if pulling from an insecure registry
auth_config: Optional transient auth config object
"""
return images.push(
_client, repo, tag, insecure_registry
)
def build(path, dockerfile='Dockerfile', **kwargs):
"""
Build an image from the specified Dockerfile found in context indicated by
`path`. If an error is encountered during streaming, a DockerException
will be raised.
**Params:**
path: string pointing to the build context. Can be any of:
* A readable directory containing a valid Dockerfile
* A tarball (optionally compressed with gzip, xz or bzip2)
* A valid Dockerfile
* A valid URL for a remote build context.
dockerfile: Name of the Dockerfile inside the context path.
Default: "Dockerfile"
kwargs: Additional `docker.Client.build` arguments
"""
return builds.build(_client, path, dockerfile, **kwargs)
get_build_id = builds.get_build_id
create_context_from_path = builds.create_context_from_path
Image = images.Image
Container = containers.Container
def get_image(id):
return Image(_client, id)
def get_container(id):
return Container(_client, id)
|