dockerapi 0.3.0 → 0.8.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/CHANGELOG.md +64 -1
- data/Gemfile.lock +1 -1
- data/README.md +248 -74
- data/bin/setup +17 -3
- data/lib/docker/api/base.rb +14 -12
- data/lib/docker/api/connection.rb +5 -13
- data/lib/docker/api/container.rb +50 -50
- data/lib/docker/api/error.rb +13 -2
- data/lib/docker/api/exec.rb +39 -0
- data/lib/docker/api/image.rb +38 -40
- data/lib/docker/api/network.rb +45 -0
- data/lib/docker/api/node.rb +26 -0
- data/lib/docker/api/response.rb +25 -0
- data/lib/docker/api/swarm.rb +40 -0
- data/lib/docker/api/system.rb +25 -3
- data/lib/docker/api/version.rb +1 -1
- data/lib/docker/api/volume.rb +11 -11
- data/lib/dockerapi.rb +8 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e010cc4d2a5c4aa102ffe7cd9d58e7e4823bf4ba9079f9a622cb021dad8cd0e
|
4
|
+
data.tar.gz: 47163ffb19a35b4a473da7f88f40d5eac418a15638ccc8d91b6b1672a1af09f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b48b06f99c46c936d4458a1908c08fe13f862ce7c63394077f52d8b621b2eb9e0be959682227f9b7ba59946f18b9098f2983a4bf1a781d16218ad66b08c730a3
|
7
|
+
data.tar.gz: ee2cb40d653054ea9bb559b9d39f43dd28556dcc25374033904f5c292403e371176ce1233636209bd5678df06f90436f6214aaafadd255d0b438cc870c318591
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,69 @@
|
|
1
|
+
# 0.8.0
|
2
|
+
|
3
|
+
Add Docker::API::Swarm methods:
|
4
|
+
* init
|
5
|
+
* update
|
6
|
+
* inspect
|
7
|
+
* unlock_key
|
8
|
+
* unlock
|
9
|
+
* join
|
10
|
+
* leave
|
11
|
+
|
12
|
+
Add Docker::API::Node methods:
|
13
|
+
* list
|
14
|
+
* inspect
|
15
|
+
* update
|
16
|
+
* delete
|
17
|
+
|
18
|
+
Query parameters and request body json can now skip the validation step with `:skip_validation => true` option.
|
19
|
+
|
20
|
+
# 0.7.0
|
21
|
+
|
22
|
+
Major changes: Docker::API::Connection is now a regular class intead of a Singleton, allowing multiple connections to be stablished within the same program (replacing the connect_to implementation). To leverage this feature, API-related classes must be initialized and may or may not receive a Docker::API::Connection as parameter, or it'll connect to /var/run/docker.sock by default. For this reason, class methods were replaced with instance methods. Documentation will reflect this changes of implementation.
|
23
|
+
|
24
|
+
Bug fix: Image push returns a 20X status even when the push is unsucessful. To prevent false positives, it now requires the authentication parameters to be provided, generating a 403 status for invalid credentials or an error if they are absent.
|
25
|
+
|
26
|
+
# 0.6.0
|
27
|
+
|
28
|
+
Add connection parameters specifications with connect_to in Docker::API::Connection.
|
29
|
+
|
30
|
+
Add Docker::API::Exec methods:
|
31
|
+
* create
|
32
|
+
* start
|
33
|
+
* resize
|
34
|
+
* inspect
|
35
|
+
|
36
|
+
# 0.5.0
|
37
|
+
|
38
|
+
Add Docker::API::System methods:
|
39
|
+
* auth
|
40
|
+
* ping
|
41
|
+
* info
|
42
|
+
* version
|
43
|
+
* events
|
44
|
+
* df
|
45
|
+
|
46
|
+
Add new response class Docker::API::Response with the following methods:
|
47
|
+
* json
|
48
|
+
* path
|
49
|
+
* success?
|
50
|
+
|
51
|
+
Error classes output better error messages.
|
52
|
+
|
53
|
+
# 0.4.0
|
54
|
+
|
55
|
+
Add Docker::API::Network methods:
|
56
|
+
* list
|
57
|
+
* inspect
|
58
|
+
* create
|
59
|
+
* remove
|
60
|
+
* prune
|
61
|
+
* connect
|
62
|
+
* disconnect
|
63
|
+
|
1
64
|
# 0.3.0
|
2
65
|
|
3
|
-
Add Docker::API::
|
66
|
+
Add Docker::API::Volume methods:
|
4
67
|
* list
|
5
68
|
* inspect
|
6
69
|
* create
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,72 +20,76 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
New implementation details as of v0.7.0.
|
24
|
+
|
23
25
|
### Images
|
24
26
|
|
25
27
|
```ruby
|
28
|
+
# Connect to local image endpoints
|
29
|
+
image = Docker::API::Image.new
|
30
|
+
|
26
31
|
# Pull from a public repository
|
27
|
-
|
32
|
+
image.create( fromImage: "nginx:latest" )
|
28
33
|
|
29
34
|
# Pull from a private repository
|
30
|
-
|
35
|
+
image.create( {fromImage: "private/repo:tag"}, {username: "janedoe", password: "password"} )
|
31
36
|
|
32
37
|
# Create image from local tar file
|
33
|
-
|
38
|
+
image.create( fromSrc: "/path/to/file.tar", repo: "repo:tag" )
|
34
39
|
|
35
40
|
# Create image from remote tar file
|
36
|
-
|
41
|
+
image.create( fromSrc: "https://url.to/file.tar", repo: "repo:tag" )
|
37
42
|
|
38
43
|
# List images
|
39
|
-
|
40
|
-
Docker::API::Image.list( all:true )
|
44
|
+
image.list
|
41
45
|
|
42
46
|
# Inspect image
|
43
|
-
|
47
|
+
image.inspect("image")
|
44
48
|
|
45
49
|
# History
|
46
|
-
|
50
|
+
image.history("image")
|
47
51
|
|
48
52
|
# Search image
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
image.search(term: "busybox", limit: 2)
|
54
|
+
image.search(term: "busybox", filters: {"is-automated": {"true": true}})
|
55
|
+
image.search(term: "busybox", filters: {"is-official": {"true": true}})
|
52
56
|
|
53
57
|
# Tag image
|
54
|
-
|
55
|
-
|
58
|
+
image.tag("current:tag", repo: "new:tag") # or
|
59
|
+
image.tag("current:tag", repo: "new", tag: "tag")
|
56
60
|
|
57
61
|
# Push image
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
image.push("repo:tag") # to dockerhub
|
63
|
+
image.push("localhost:5000/repo:tag") # to local registry
|
64
|
+
image.push("private/repo", {tag: "tag"}, {username: "janedoe", password: "password"} # to private repository
|
61
65
|
|
62
|
-
# Remove
|
63
|
-
|
64
|
-
|
66
|
+
# Remove image
|
67
|
+
image.remove("image")
|
68
|
+
image.remove("image", force: true)
|
65
69
|
|
66
70
|
# Remove unsued images (prune)
|
67
|
-
|
71
|
+
image.prune(filters: {dangling: {"false": true}})
|
68
72
|
|
69
73
|
# Create image from a container (commit)
|
70
|
-
|
74
|
+
image.commit(container: container, repo: "my/image", tag: "latest", comment: "Comment from commit", author: "dockerapi", pause: false )
|
71
75
|
|
72
76
|
# Build image from a local tar file
|
73
|
-
|
77
|
+
image.build("/path/to/file.tar")
|
74
78
|
|
75
79
|
# Build image from a remote tar file
|
76
|
-
|
80
|
+
image.build(nil, remote: "https://url.to/file.tar")
|
77
81
|
|
78
82
|
# Build image from a remote Dockerfile
|
79
|
-
|
83
|
+
image.build(nil, remote: "https://url.to/Dockerfile")
|
80
84
|
|
81
85
|
# Delete builder cache
|
82
|
-
|
86
|
+
image.delete_cache
|
83
87
|
|
84
88
|
# Export repo
|
85
|
-
|
89
|
+
image.export("repo:tag", "~/exported_image.tar")
|
86
90
|
|
87
91
|
# Import repo
|
88
|
-
|
92
|
+
image.import("/path/to/file.tar")
|
89
93
|
```
|
90
94
|
|
91
95
|
### Containers
|
@@ -94,82 +98,227 @@ Let's test a Nginx container
|
|
94
98
|
|
95
99
|
```ruby
|
96
100
|
# Pull nginx image
|
97
|
-
Docker::API::Image.create( fromImage: "nginx:latest" )
|
101
|
+
Docker::API::Image.new.create( fromImage: "nginx:latest" )
|
102
|
+
|
103
|
+
# Connect to local container endpoints
|
104
|
+
container = Docker::API::Container.new
|
98
105
|
|
99
106
|
# Create container
|
100
|
-
|
107
|
+
container.create( {name: "nginx"}, {Image: "nginx:latest", HostConfig: {PortBindings: {"80/tcp": [ {HostIp: "0.0.0.0", HostPort: "80"} ]}}})
|
101
108
|
|
102
109
|
# Start container
|
103
|
-
|
110
|
+
container.start("nginx")
|
104
111
|
|
105
112
|
# Open localhost or machine IP to check the container running
|
106
113
|
|
107
114
|
# Restart container
|
108
|
-
|
115
|
+
container.restart("nginx")
|
109
116
|
|
110
117
|
# Pause/unpause container
|
111
|
-
|
112
|
-
|
118
|
+
container.pause("nginx")
|
119
|
+
container.unpause("nginx")
|
113
120
|
|
114
121
|
# List containers
|
115
|
-
|
122
|
+
container.list
|
116
123
|
|
117
124
|
# List containers (including stopped ones)
|
118
|
-
|
125
|
+
container.list(all: true)
|
119
126
|
|
120
127
|
# Inspect container
|
121
|
-
|
128
|
+
container.inspect("nginx")
|
122
129
|
|
123
130
|
# View container's processes
|
124
|
-
|
131
|
+
container.top("nginx")
|
125
132
|
|
126
|
-
#
|
127
|
-
|
133
|
+
# Using json output
|
134
|
+
container.top("nginx").json
|
128
135
|
|
129
136
|
# View filesystem changes
|
130
|
-
|
137
|
+
container.changes("nginx")
|
131
138
|
|
132
139
|
# View filesystem logs
|
133
|
-
|
134
|
-
|
140
|
+
container.logs("nginx", stdout: true)
|
141
|
+
container.logs("nginx", stdout: true, follow: true)
|
135
142
|
|
136
143
|
# View filesystem stats
|
137
|
-
|
144
|
+
container.stats("nginx", stream: true)
|
138
145
|
|
139
146
|
# Export container
|
140
|
-
|
147
|
+
container.export("nginx", "~/exported_container")
|
141
148
|
|
142
149
|
# Get files from container
|
143
|
-
|
150
|
+
container.archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
|
144
151
|
|
145
152
|
# Stop container
|
146
|
-
|
153
|
+
container.stop("nginx")
|
147
154
|
|
148
155
|
# Remove container
|
149
|
-
|
156
|
+
container.remove("nginx")
|
150
157
|
|
151
158
|
# Remove stopped containers (prune)
|
152
|
-
|
159
|
+
container.prune
|
153
160
|
```
|
154
161
|
|
155
162
|
### Volumes
|
156
163
|
|
157
164
|
```ruby
|
165
|
+
# Connect to local volume endpoints
|
166
|
+
volume = Docker::API::Volume.new
|
167
|
+
|
158
168
|
# Create volume
|
159
|
-
|
169
|
+
volume.create( Name:"my-volume" )
|
160
170
|
|
161
171
|
# List volumes
|
162
|
-
|
172
|
+
volume.list
|
163
173
|
|
164
174
|
# Inspect volume
|
165
|
-
|
175
|
+
volume.inspect("my-volume")
|
166
176
|
|
167
177
|
# Remove volume
|
168
|
-
|
178
|
+
volume.remove("my-volume")
|
169
179
|
|
170
180
|
# Remove unused volumes (prune)
|
171
|
-
|
181
|
+
volume.prune
|
182
|
+
```
|
183
|
+
|
184
|
+
### Network
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
# Connect to local network endpoints
|
188
|
+
network = Docker::API::Network.new
|
189
|
+
|
190
|
+
# List networks
|
191
|
+
network.list
|
172
192
|
|
193
|
+
# Inspect network
|
194
|
+
network.inspect("bridge")
|
195
|
+
|
196
|
+
# Create network
|
197
|
+
network.create( Name:"my-network" )
|
198
|
+
|
199
|
+
# Remove network
|
200
|
+
network.remove("my-network")
|
201
|
+
|
202
|
+
# Remove unused network (prune)
|
203
|
+
network.prune
|
204
|
+
|
205
|
+
# Connect container to a network
|
206
|
+
network.connect( "my-network", Container: "my-container" )
|
207
|
+
|
208
|
+
# Disconnect container to a network
|
209
|
+
network.disconnect( "my-network", Container: "my-container" )
|
210
|
+
```
|
211
|
+
|
212
|
+
### System
|
213
|
+
|
214
|
+
```ruby
|
215
|
+
# Connect to local system endpoints
|
216
|
+
sys = Docker::API::System.new
|
217
|
+
|
218
|
+
# Ping docker api
|
219
|
+
sys.ping
|
220
|
+
|
221
|
+
# Docker components versions
|
222
|
+
sys.version
|
223
|
+
|
224
|
+
# System info
|
225
|
+
sys.info
|
226
|
+
|
227
|
+
# System events (stream)
|
228
|
+
sys.events(until: Time.now.to_i)
|
229
|
+
|
230
|
+
# Data usage information
|
231
|
+
sys.df
|
232
|
+
```
|
233
|
+
|
234
|
+
### Exec
|
235
|
+
|
236
|
+
```ruby
|
237
|
+
# Connect to local exec endpoints
|
238
|
+
exe = Docker::API::Exec.new
|
239
|
+
|
240
|
+
# Create exec instance, get generated exec ID
|
241
|
+
response = exe.create(container, AttachStdout:true, Cmd: ["ls", "-l"])
|
242
|
+
id = response.json["Id"]
|
243
|
+
|
244
|
+
# Execute the command, stream from Stdout is stored in response data
|
245
|
+
response = exe.start(id)
|
246
|
+
print response.data[:stream]
|
247
|
+
|
248
|
+
# Inspect exec instance
|
249
|
+
exe.inspect(id)
|
250
|
+
```
|
251
|
+
|
252
|
+
### Swarm
|
253
|
+
```ruby
|
254
|
+
# Connect to local swarm endpoints
|
255
|
+
swarm = Docker::API::Swarm.new
|
256
|
+
|
257
|
+
# Init swarm
|
258
|
+
swarm.init({AdvertiseAddr: "local-ip-address:2377", ListenAddr: "0.0.0.0:4567"})
|
259
|
+
|
260
|
+
# Inspect swarm
|
261
|
+
swarm.inspect
|
262
|
+
|
263
|
+
# Update swarm
|
264
|
+
swarm.update(version, {rotateWorkerToken: true})
|
265
|
+
swarm.update(version, {rotateManagerToken: true})
|
266
|
+
swarm.update(version, {rotateManagerUnlockKey: true})
|
267
|
+
swarm.update(version, {EncryptionConfig: { AutoLockManagers: true }})
|
268
|
+
|
269
|
+
# Get unlock key
|
270
|
+
swarm.unlock_key
|
271
|
+
|
272
|
+
# Unlock swarm
|
273
|
+
swarm.unlock(UnlockKey: "key-value")
|
274
|
+
|
275
|
+
# Join an existing swarm
|
276
|
+
swarm.join(RemoteAddrs: ["remote-manager-address:2377"], JoinToken: "Join-Token-Here")
|
277
|
+
|
278
|
+
# Leave a swarm
|
279
|
+
swarm.leave(force: true)
|
280
|
+
```
|
281
|
+
|
282
|
+
### Node
|
283
|
+
```ruby
|
284
|
+
# Connect to local node endpoints
|
285
|
+
node = Docker::API::Node.new
|
286
|
+
|
287
|
+
# List nodes
|
288
|
+
node.list
|
289
|
+
|
290
|
+
# Inspect node
|
291
|
+
node.inspect("node-id")
|
292
|
+
|
293
|
+
# Update node (version, Role and Availability must be present)
|
294
|
+
node.update("node-id", {version: "version"}, {Role: "worker", Availability: "pause" })
|
295
|
+
node.update("node-id", {version: "version"}, {Role: "worker", Availability: "active" })
|
296
|
+
node.update("node-id", {version: "version"}, {Role: "manager", Availability: "active" })
|
297
|
+
|
298
|
+
# Delete node
|
299
|
+
node.delete("node-id")
|
300
|
+
```
|
301
|
+
|
302
|
+
### Connection
|
303
|
+
|
304
|
+
By default Docker::API::Connection will connect to local Docker socket at `/var/run/docker.sock`. See examples below to use a different path or connect to a remote address.
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
# Setting different connections
|
308
|
+
local = Docker::API::Connection.new('unix:///', socket: "/path/to/docker.sock")
|
309
|
+
remote = Docker::API::Connection.new("http://127.0.0.1:2375") # change the IP address accordingly
|
310
|
+
|
311
|
+
# Using default /var/run/docker.sock
|
312
|
+
image_default = Docker::API::Image.new
|
313
|
+
image_default.list
|
314
|
+
|
315
|
+
# Using custom socket path
|
316
|
+
image_custom = Docker::API::Image.new(local)
|
317
|
+
image_custom.list
|
318
|
+
|
319
|
+
# Using remote address
|
320
|
+
image_remote = Docker::API::Image.new(remote)
|
321
|
+
image_remote.list
|
173
322
|
```
|
174
323
|
|
175
324
|
### Requests
|
@@ -178,7 +327,41 @@ Requests should work as described in [Docker API documentation](https://docs.doc
|
|
178
327
|
|
179
328
|
### Response
|
180
329
|
|
181
|
-
All requests return a Excon::Response
|
330
|
+
All requests return a response class that inherits from Excon::Response. Available attribute readers and methods include: `status`, `data`, `body`, `headers`, `json`, `path`, `success?`.
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
response = Docker::API::Image.new.create(fromImage: "busybox:latest")
|
334
|
+
|
335
|
+
response
|
336
|
+
=> #<Docker::API::Response:0x000055bb390b35c0 ... >
|
337
|
+
|
338
|
+
response.status
|
339
|
+
=> 200
|
340
|
+
|
341
|
+
response.data
|
342
|
+
=> {:body=>"...", :cookies=>[], :host=>nil, :headers=>{ ... }, :path=>"/images/create?fromImage=busybox:latest", :port=>nil, :status=>200, :status_line=>"HTTP/1.1 200 OK\r\n", :reason_phrase=>"OK"}
|
343
|
+
|
344
|
+
response.headers
|
345
|
+
=> {"Api-Version"=>"1.40", "Content-Type"=>"application/json", "Docker-Experimental"=>"false", "Ostype"=>"linux", "Server"=>"Docker/19.03.11 (linux)", "Date"=>"Mon, 29 Jun 2020 16:10:06 GMT"}
|
346
|
+
|
347
|
+
response.body
|
348
|
+
=> "{\"status\":\"Pulling from library/busybox\" ... "
|
349
|
+
|
350
|
+
response.json
|
351
|
+
=> [{:status=>"Pulling from library/busybox", :id=>"latest"}, {:status=>"Pulling fs layer", :progressDetail=>{}, :id=>"76df9210b28c"}, ... , {:status=>"Status: Downloaded newer image for busybox:latest"}]
|
352
|
+
|
353
|
+
response.path
|
354
|
+
=> "/images/create?fromImage=busybox:latest"
|
355
|
+
|
356
|
+
response.success?
|
357
|
+
=> true
|
358
|
+
```
|
359
|
+
|
360
|
+
### Error handling
|
361
|
+
|
362
|
+
`Docker::API::InvalidParameter` and `Docker::API::InvalidRequestBody` may be raised when an invalid option is passed as argument (ie: an option not described in Docker API documentation for request query parameters nor request body (json) parameters). Even if no errors were raised, consider validating the status code and/or message of the response to check if the Docker daemon has fulfilled the operation properly.
|
363
|
+
|
364
|
+
To completely skip the validation process, add `:skip_validation => true` in the hash to be validated.
|
182
365
|
|
183
366
|
## Development
|
184
367
|
|
@@ -188,28 +371,19 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
188
371
|
|
189
372
|
### Road to 1.0.0
|
190
373
|
|
191
|
-
NS: Not Started
|
192
|
-
|
193
|
-
WIP: Work In Progress
|
194
|
-
|
195
|
-
|
196
374
|
| Class | Tests | Implementation | Refactoring |
|
197
375
|
|---|---|---|---|
|
198
|
-
| Container | Ok | Ok |
|
199
|
-
| Image | Ok | Ok |
|
200
|
-
| Volume | Ok | Ok |
|
201
|
-
| Network |
|
202
|
-
| System |
|
203
|
-
| Exec |
|
204
|
-
| Swarm |
|
205
|
-
| Node |
|
206
|
-
| Service |
|
207
|
-
| Task |
|
208
|
-
| Secret |
|
209
|
-
|
210
|
-
Misc:
|
211
|
-
* Improve response object
|
212
|
-
* Improve error objects
|
376
|
+
| Container | Ok | Ok | 7/24 |
|
377
|
+
| Image | Ok | Ok | 7/31 |
|
378
|
+
| Volume | Ok | Ok | 8/7 |
|
379
|
+
| Network | Ok | Ok | 8/7 |
|
380
|
+
| System | Ok | Ok | 8/7 |
|
381
|
+
| Exec | Ok | Ok | 8/7 |
|
382
|
+
| Swarm | Ok | Ok | 8/14 |
|
383
|
+
| Node | Ok | Ok | 8/14 |
|
384
|
+
| Service | 7/17 | 7/17 | 8/14 |
|
385
|
+
| Task | 7/17 | 7/17 | 8/14 |
|
386
|
+
| Secret | 7/17 | 7/17 | 8/14 |
|
213
387
|
|
214
388
|
## Contributing
|
215
389
|
|