dockerapi 0.13.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +35 -0
- data/Gemfile.lock +3 -3
- data/README.md +73 -23
- data/bin/setup +9 -1
- data/dockerapi.gemspec +5 -4
- data/lib/docker/api/base.rb +64 -20
- data/lib/docker/api/connection.rb +23 -17
- data/lib/docker/api/container.rb +306 -144
- data/lib/docker/api/error.rb +19 -3
- data/lib/docker/api/exec.rb +49 -36
- data/lib/docker/api/image.rb +32 -14
- data/lib/docker/api/network.rb +84 -48
- data/lib/docker/api/node.rb +47 -28
- data/lib/docker/api/response.rb +27 -19
- data/lib/docker/api/secret.rb +1 -9
- data/lib/docker/api/service.rb +3 -18
- data/lib/docker/api/swarm.rb +70 -36
- data/lib/docker/api/system.rb +57 -24
- data/lib/docker/api/task.rb +10 -10
- data/lib/docker/api/version.rb +1 -1
- data/lib/docker/api/volume.rb +56 -37
- data/lib/dockerapi.rb +8 -1
- metadata +10 -7
- data/.travis.yml +0 -6
data/lib/docker/api/container.rb
CHANGED
@@ -1,148 +1,310 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
def list params = {}
|
6
|
-
@connection.get(build_path(["json"], params))
|
7
|
-
end
|
8
|
-
|
9
|
-
def details name, params = {}
|
10
|
-
@connection.get(build_path([name, "json"], params))
|
11
|
-
end
|
12
|
-
|
13
|
-
def top name, params = {}
|
14
|
-
@connection.get(build_path([name, "top"], params))
|
15
|
-
end
|
16
|
-
|
17
|
-
def changes name
|
18
|
-
@connection.get(build_path([name, "changes"]))
|
19
|
-
end
|
20
|
-
|
21
|
-
def start name, params = {}
|
22
|
-
@connection.post(build_path([name, "start"], params))
|
23
|
-
end
|
24
|
-
|
25
|
-
def stop name, params = {}
|
26
|
-
@connection.post(build_path([name, "stop"], params))
|
27
|
-
end
|
28
|
-
|
29
|
-
def restart name, params = {}
|
30
|
-
@connection.post(build_path([name, "restart"], params))
|
31
|
-
end
|
32
|
-
|
33
|
-
def kill name, params = {}
|
34
|
-
@connection.post(build_path([name, "kill"], params))
|
35
|
-
end
|
36
|
-
|
37
|
-
def wait name, params = {}
|
38
|
-
@connection.post(build_path([name, "wait"], params))
|
39
|
-
end
|
40
|
-
|
41
|
-
def update name, body = {}
|
42
|
-
@connection.request(method: :post, path: build_path([name, "update"]), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
43
|
-
end
|
44
|
-
|
45
|
-
def rename name, params = {}
|
46
|
-
@connection.post(build_path([name, "rename"], params))
|
47
|
-
end
|
48
|
-
|
49
|
-
def resize name, params = {}
|
50
|
-
@connection.post(build_path([name, "resize"], params))
|
51
|
-
end
|
52
|
-
|
53
|
-
def prune params = {}
|
54
|
-
@connection.post(build_path(["prune"], params))
|
55
|
-
end
|
56
|
-
|
57
|
-
def pause name
|
58
|
-
@connection.post(build_path([name, "pause"]))
|
59
|
-
end
|
60
|
-
|
61
|
-
def unpause name
|
62
|
-
@connection.post(build_path([name, "unpause"]))
|
63
|
-
end
|
64
|
-
|
65
|
-
def remove name, params = {}
|
66
|
-
@connection.delete(build_path([name]))
|
67
|
-
end
|
68
|
-
|
69
|
-
def logs name, params = {}
|
70
|
-
|
71
|
-
path = build_path([name, "logs"], params)
|
72
|
-
|
73
|
-
if params[:follow] == true || params[:follow] == 1
|
74
|
-
@connection.request(method: :get, path: path , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
75
|
-
else
|
76
|
-
@connection.get(path)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def attach name, params = {}
|
81
|
-
@connection.request(method: :post, path: build_path([name, "attach"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| puts chunk.inspect })
|
82
|
-
end
|
83
|
-
|
84
|
-
def create params = {}, body = {}
|
85
|
-
@connection.request(method: :post, path: build_path(["create"], params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
86
|
-
end
|
87
|
-
|
88
|
-
def stats name, params = {}
|
89
|
-
path = build_path([name, "stats"], params)
|
90
|
-
|
91
|
-
if params[:stream] == true || params[:stream] == 1
|
92
|
-
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
93
|
-
puts chunk
|
94
|
-
end
|
95
|
-
@connection.request(method: :get, path: path , response_block: streamer)
|
96
|
-
else
|
97
|
-
@connection.get(path)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def export name, path = "exported_container"
|
102
|
-
response = self.details(name)
|
103
|
-
if response.status == 200
|
104
|
-
file = File.open(File.expand_path(path), "wb")
|
105
|
-
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
106
|
-
file.write(chunk)
|
107
|
-
end
|
108
|
-
response = @connection.request(method: :get, path: build_path([name, "export"]) , response_block: streamer)
|
109
|
-
file.close
|
110
|
-
end
|
111
|
-
response
|
112
|
-
end
|
113
|
-
|
114
|
-
def archive name, file, params = {}
|
115
|
-
|
116
|
-
begin # File exists on disk, send it to container
|
117
|
-
file = File.open( File.expand_path( file ) , "r")
|
118
|
-
response = @connection.request(method: :put, path: build_path([name, "archive"], params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
119
|
-
file.close
|
120
|
-
rescue Errno::ENOENT # File doesnt exist, get it from container
|
121
|
-
response = @connection.head(build_path([name, "archive"], params))
|
122
|
-
if response.status == 200 # file exists in container
|
123
|
-
file = File.open( File.expand_path( file ) , "wb")
|
124
|
-
response = @connection.request(method: :get, path: build_path([name, "archive"], params) , response_block: lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
|
125
|
-
file.close
|
126
|
-
end
|
127
|
-
end
|
128
|
-
response
|
129
|
-
end
|
130
|
-
|
131
|
-
#################################################
|
132
|
-
# Items in this area to be removed before 1.0.0 #
|
133
|
-
#################################################
|
134
|
-
def base_path
|
135
|
-
"/containers"
|
136
|
-
end
|
137
|
-
|
138
|
-
def inspect *args
|
139
|
-
return super.inspect if args.size == 0
|
140
|
-
warn "WARNING: #inspect is deprecated and will be removed in the future, please use #details instead."
|
141
|
-
name, params = args[0], args[1] || {}
|
142
|
-
details(name, params)
|
143
|
-
end
|
144
|
-
#################################################
|
1
|
+
##
|
2
|
+
# This class represents the Docker API endpoints regarding containers.
|
3
|
+
# @see https://docs.docker.com/engine/api/v1.40/#tag/Container
|
4
|
+
class Docker::API::Container < Docker::API::Base
|
145
5
|
|
6
|
+
##
|
7
|
+
# Return a list of containers.
|
8
|
+
#
|
9
|
+
# Docker API: GET /containers/json
|
10
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerList
|
11
|
+
#
|
12
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
13
|
+
def list params = {}
|
14
|
+
@connection.get(build_path("/containers/json", params))
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Return low-level information about a container.
|
19
|
+
#
|
20
|
+
# Docker API: GET /containers/{id}/json
|
21
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerInspect
|
22
|
+
#
|
23
|
+
# @param name [String]: The ID or name of the container.
|
24
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
25
|
+
def details name, params = {}
|
26
|
+
@connection.get(build_path("/containers/#{name}/json", params))
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# List processes running inside a container.
|
31
|
+
#
|
32
|
+
# Docker API: GET /containers/{id}/top
|
33
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerTop
|
34
|
+
#
|
35
|
+
# @param name [String]: The ID or name of the container.
|
36
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
37
|
+
def top name, params = {}
|
38
|
+
@connection.get(build_path("/containers/#{name}/top", params))
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Get changes on a container’s filesystem.
|
43
|
+
#
|
44
|
+
# Docker API: GET /containers/{id}/changes
|
45
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerChanges
|
46
|
+
#
|
47
|
+
# @param name [String]: The ID or name of the container.
|
48
|
+
def changes name
|
49
|
+
@connection.get("/containers/#{name}/changes")
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Start a container.
|
54
|
+
#
|
55
|
+
# Docker API: POST /containers/{id}/start
|
56
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerStart
|
57
|
+
#
|
58
|
+
# @param name [String]: The ID or name of the container.
|
59
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
60
|
+
def start name, params = {}
|
61
|
+
@connection.post(build_path("/containers/#{name}/start", params))
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Stop a container.
|
66
|
+
#
|
67
|
+
# Docker API: POST /containers/{id}/stop
|
68
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerStop
|
69
|
+
#
|
70
|
+
# @param name [String]: The ID or name of the container.
|
71
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
72
|
+
def stop name, params = {}
|
73
|
+
@connection.post(build_path("/containers/#{name}/stop", params))
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Restart a container.
|
78
|
+
#
|
79
|
+
# Docker API: POST /containers/{id}/restart
|
80
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerRestart
|
81
|
+
#
|
82
|
+
# @param name [String]: The ID or name of the container.
|
83
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
84
|
+
def restart name, params = {}
|
85
|
+
@connection.post(build_path("/containers/#{name}/restart", params))
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Send a POSIX signal to a container, defaulting to killing to the container.
|
90
|
+
#
|
91
|
+
# Docker API: POST /containers/{id}/kill
|
92
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerKill
|
93
|
+
#
|
94
|
+
# @param name [String]: The ID or name of the container.
|
95
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
96
|
+
def kill name, params = {}
|
97
|
+
@connection.post(build_path("/containers/#{name}/kill", params))
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# Block until a container stops, then returns the exit code.
|
102
|
+
#
|
103
|
+
# Docker API: POST /containers/{id}/wait
|
104
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerWait
|
105
|
+
#
|
106
|
+
# @param name [String]: The ID or name of the container.
|
107
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
108
|
+
def wait name, params = {}
|
109
|
+
@connection.post(build_path("/containers/#{name}/wait", params))
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Change various configuration options of a container without having to recreate it.
|
114
|
+
#
|
115
|
+
# Docker API: POST /containers/{id}/update
|
116
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerUpdate
|
117
|
+
#
|
118
|
+
# @param name [String]: The ID or name of the container.
|
119
|
+
# @param body [Hash]: Request body to be sent as json.
|
120
|
+
def update name, body = {}
|
121
|
+
@connection.request(method: :post, path: "/containers/#{name}/update", headers: {"Content-Type": "application/json"}, body: body.to_json)
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Rename a container.
|
126
|
+
#
|
127
|
+
# Docker API: POST /containers/{id}/rename
|
128
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerRename
|
129
|
+
#
|
130
|
+
# @param name [String]: The ID or name of the container.
|
131
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
132
|
+
def rename name, params = {}
|
133
|
+
@connection.post(build_path("/containers/#{name}/rename", params))
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Resize the TTY for a container.
|
138
|
+
#
|
139
|
+
# Docker API: POST /containers/{id}/resize
|
140
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerResize
|
141
|
+
#
|
142
|
+
# @param name [String]: The ID or name of the container.
|
143
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
144
|
+
def resize name, params = {}
|
145
|
+
@connection.post(build_path("/containers/#{name}/resize", params))
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Delete stopped containers.
|
150
|
+
#
|
151
|
+
# Docker API: POST /containers/prune
|
152
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerPrune
|
153
|
+
#
|
154
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
155
|
+
def prune params = {}
|
156
|
+
@connection.post(build_path("/containers/prune", params))
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# Pause a container.
|
161
|
+
#
|
162
|
+
# Docker API: POST /containers/{id}/pause
|
163
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerPause
|
164
|
+
#
|
165
|
+
# @param name [String]: The ID or name of the container.
|
166
|
+
def pause name
|
167
|
+
@connection.post("/containers/#{name}/pause")
|
168
|
+
end
|
169
|
+
|
170
|
+
##
|
171
|
+
# Resume a container which has been paused.
|
172
|
+
#
|
173
|
+
# Docker API: POST /containers/{id}/unpause
|
174
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerUnpause
|
175
|
+
#
|
176
|
+
# @param name [String]: The ID or name of the container.
|
177
|
+
def unpause name
|
178
|
+
@connection.post("/containers/#{name}/unpause")
|
179
|
+
end
|
180
|
+
|
181
|
+
##
|
182
|
+
# Remove a container.
|
183
|
+
#
|
184
|
+
# Docker API: DELETE /containers/{id}
|
185
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerDelete
|
186
|
+
#
|
187
|
+
# @param name [String]: The ID or name of the container.
|
188
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
189
|
+
def remove name, params = {}
|
190
|
+
@connection.delete(build_path("/containers/#{name}", params))
|
191
|
+
end
|
192
|
+
|
193
|
+
##
|
194
|
+
# Get stdout and stderr logs from a container.
|
195
|
+
#
|
196
|
+
# Docker API: GET /containers/{id}/logs
|
197
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerLogs
|
198
|
+
#
|
199
|
+
# @param name [String]: The ID or name of the container.
|
200
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
201
|
+
# @param &block: Replace the default output to stdout behavior.
|
202
|
+
def logs name, params = {}, &block
|
203
|
+
|
204
|
+
path = build_path("/containers/#{name}/logs", params)
|
205
|
+
|
206
|
+
if [true, 1 ].include? params[:follow]
|
207
|
+
@connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
|
208
|
+
else
|
209
|
+
@connection.get(path)
|
146
210
|
end
|
147
211
|
end
|
212
|
+
|
213
|
+
##
|
214
|
+
# Attach to a container.
|
215
|
+
#
|
216
|
+
# Docker API: POST /containers/{id}/attach
|
217
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerAttach
|
218
|
+
#
|
219
|
+
# @param name [String]: The ID or name of the container.
|
220
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
221
|
+
# @param &block: Replace the default output to stdout behavior.
|
222
|
+
def attach name, params = {}, &block
|
223
|
+
@connection.request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer)
|
224
|
+
end
|
225
|
+
|
226
|
+
##
|
227
|
+
# Create a container.
|
228
|
+
#
|
229
|
+
# Docker API: POST /containers/create
|
230
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerCreate
|
231
|
+
#
|
232
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
233
|
+
# @param body [Hash]: Request body to be sent as json.
|
234
|
+
def create params = {}, body = {}
|
235
|
+
@connection.request(method: :post, path: build_path("/containers/create", params), headers: {"Content-Type": "application/json"}, body: body.to_json)
|
236
|
+
end
|
237
|
+
|
238
|
+
##
|
239
|
+
# Get container stats based on resource usage.
|
240
|
+
#
|
241
|
+
# Docker API: GET /containers/{id}/stats
|
242
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerStats
|
243
|
+
#
|
244
|
+
# @param name [String]: The ID or name of the container.
|
245
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
246
|
+
# @param &block: Replace the default output to stdout behavior.
|
247
|
+
def stats name, params = {}, &block
|
248
|
+
path = build_path("/containers/#{name}/stats", params)
|
249
|
+
if [true, 1 ].include? params[:stream]
|
250
|
+
@connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer)
|
251
|
+
else
|
252
|
+
@connection.get(path)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
##
|
257
|
+
# Export the contents of a container as a tarball.
|
258
|
+
#
|
259
|
+
# Docker API: GET /containers/{id}/export
|
260
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerExport
|
261
|
+
#
|
262
|
+
# @param name [String]: The ID or name of the container.
|
263
|
+
# @param path [String]: Path to the exportated file.
|
264
|
+
# @param &block: Replace the default file writing behavior.
|
265
|
+
def export name, path, &block
|
266
|
+
response = self.details(name)
|
267
|
+
return response unless response.status == 200
|
268
|
+
@connection.request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path))
|
269
|
+
end
|
270
|
+
|
271
|
+
##
|
272
|
+
# Get an archive of a filesystem resource in a container.
|
273
|
+
#
|
274
|
+
# Get a tar archive of a resource in the filesystem of container id.
|
275
|
+
#
|
276
|
+
# Docker API: GET /containers/{id}/archive
|
277
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/ContainerArchive
|
278
|
+
#
|
279
|
+
# @param name [String]: The ID or name of the container.
|
280
|
+
# @param path [String]: Path to the exportated file.
|
281
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
282
|
+
# @param &block: Replace the default file writing behavior.
|
283
|
+
def get_archive name, path, params = {}, &block
|
284
|
+
response = @connection.head(build_path("/containers/#{name}/archive", params))
|
285
|
+
return response unless response.status == 200
|
286
|
+
|
287
|
+
file = File.open( File.expand_path( path ) , "wb")
|
288
|
+
response = @connection.request(method: :get, path: build_path("/containers/#{name}/archive", params) , response_block: block_given? ? block : lambda { |chunk, remaining_bytes, total_bytes| file.write(chunk) })
|
289
|
+
file.close
|
290
|
+
response
|
291
|
+
end
|
292
|
+
|
293
|
+
##
|
294
|
+
# Extract an archive of files or folders to a directory in a container.
|
295
|
+
#
|
296
|
+
# Upload a tar archive to be extracted to a path in the filesystem of container id.
|
297
|
+
#
|
298
|
+
# Docker API: PUT /containers/{id}/archive
|
299
|
+
# @see https://docs.docker.com/engine/api/v1.40/#operation/PutContainerArchive
|
300
|
+
#
|
301
|
+
# @param name [String]: The ID or name of the container.
|
302
|
+
# @param path [String]: Path of the tar file.
|
303
|
+
# @param params [Hash]: Parameters that are appended to the URL.
|
304
|
+
def put_archive name, path, params = {}
|
305
|
+
file = File.open( File.expand_path( path ) , "r")
|
306
|
+
response = @connection.request(method: :put, path: build_path("/containers/#{name}/archive", params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} )
|
307
|
+
file.close
|
308
|
+
response
|
309
|
+
end
|
148
310
|
end
|