docker-api-ng 0.3.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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +202 -0
  3. data/NOTICE +12 -0
  4. data/README.md +278 -0
  5. data/docker-api-ng.gemspec +42 -0
  6. data/docs/building-images.md +98 -0
  7. data/docs/connecting.md +111 -0
  8. data/docs/errors.md +89 -0
  9. data/docs/exec.md +100 -0
  10. data/docs/extending.md +109 -0
  11. data/docs/migrating-from-docker-api.md +156 -0
  12. data/docs/streaming.md +91 -0
  13. data/lib/docker/api/auth.rb +154 -0
  14. data/lib/docker/api/body.rb +47 -0
  15. data/lib/docker/api/client.rb +117 -0
  16. data/lib/docker/api/collection.rb +60 -0
  17. data/lib/docker/api/collections/containers.rb +78 -0
  18. data/lib/docker/api/collections/images.rb +221 -0
  19. data/lib/docker/api/collections/networks.rb +85 -0
  20. data/lib/docker/api/collections/system.rb +98 -0
  21. data/lib/docker/api/collections/volumes.rb +54 -0
  22. data/lib/docker/api/config.rb +163 -0
  23. data/lib/docker/api/connection.rb +333 -0
  24. data/lib/docker/api/context.rb +124 -0
  25. data/lib/docker/api/errors.rb +159 -0
  26. data/lib/docker/api/operations.rb +3064 -0
  27. data/lib/docker/api/path.rb +33 -0
  28. data/lib/docker/api/platform.rb +68 -0
  29. data/lib/docker/api/query.rb +76 -0
  30. data/lib/docker/api/resource.rb +174 -0
  31. data/lib/docker/api/resources/container.rb +378 -0
  32. data/lib/docker/api/resources/exec.rb +48 -0
  33. data/lib/docker/api/resources/image.rb +209 -0
  34. data/lib/docker/api/resources/network.rb +90 -0
  35. data/lib/docker/api/resources/volume.rb +51 -0
  36. data/lib/docker/api/response.rb +110 -0
  37. data/lib/docker/api/session.rb +70 -0
  38. data/lib/docker/api/stream.rb +142 -0
  39. data/lib/docker/api/tar.rb +157 -0
  40. data/lib/docker/api/transport/base.rb +62 -0
  41. data/lib/docker/api/transport/fake.rb +154 -0
  42. data/lib/docker/api/transport/named_pipe.rb +58 -0
  43. data/lib/docker/api/transport/tcp.rb +49 -0
  44. data/lib/docker/api/transport/tls.rb +84 -0
  45. data/lib/docker/api/transport/unix.rb +35 -0
  46. data/lib/docker/api/transport.rb +113 -0
  47. data/lib/docker/api/version.rb +21 -0
  48. data/lib/docker/api.rb +68 -0
  49. data/sig/docker/api/core.rbs +109 -0
  50. data/sig/docker/api/operations.rbs +123 -0
  51. metadata +97 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9b5f85c245e02ac2d11b5225e5a89b49b4a9ec9bfd2631e44536cb3c57322538
4
+ data.tar.gz: b6256d3d50edc2ae22b6402959b8480e5f9f36ac4b6ea1901030f82bc4306550
5
+ SHA512:
6
+ metadata.gz: 57dc554cbea32034ba42e6d76b565d4fa1dcf5fc145aa3471a091caf233e57d407e80d3fb0fff99f934f3e94fe7f3ada0d539cbdf876fa47eece895b4237f089
7
+ data.tar.gz: d5e3feab0727f4528cb036681753389c8d9c3463939ad2614821bab65a9bea20d1138a77d6209865446fb3f40e3fb14b5efcbf189e7f35a407c0b4c5062b09cc
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ docker-api-ng
2
+ Copyright 2026 Tim Smith
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ This product includes a vendored copy of the Docker Engine API
11
+ specification (data/swagger/), which is part of the Moby Project and is
12
+ licensed under the Apache License, Version 2.0.
data/README.md ADDED
@@ -0,0 +1,278 @@
1
+ # docker-api-ng
2
+
3
+ A Ruby client for the modern Docker Engine API.
4
+
5
+ - **No runtime dependencies.** Everything it needs ships with Ruby.
6
+ - **Complete API coverage, by construction.** All 108 Engine API operations are
7
+ generated from Docker's own OpenAPI specification, so nothing is missing and
8
+ keeping up with Docker is a reviewable diff rather than manual archaeology.
9
+ - **An ergonomic layer on top.** Collections and resource objects for the things
10
+ you touch every day, with the generated layer underneath whenever you need
11
+ something it has not grown sugar for.
12
+ - **Testable without a daemon.** The whole client can be driven by a scripted
13
+ transport, so tests are fast, hermetic and honest.
14
+
15
+ ```ruby
16
+ require "docker/api"
17
+
18
+ client = Docker::API::Client.new
19
+
20
+ client.images.pull("alpine:3.20")
21
+ container = client.containers.create(image: "alpine:3.20", name: "hello", cmd: %w{sleep 60})
22
+ container.start
23
+
24
+ result = container.exec(%w{cat /etc/alpine-release})
25
+ result.stdout #=> "3.20.3\n"
26
+ result.exit_code #=> 0
27
+
28
+ container.remove(force: true)
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ ```ruby
34
+ gem "docker-api-ng"
35
+ ```
36
+
37
+ Requires Ruby 3.1 or newer and a daemon speaking Engine API v1.41 or newer
38
+ (Docker 20.10+).
39
+
40
+ ## Connecting
41
+
42
+ With no arguments, a client resolves its daemon the way the `docker` CLI does:
43
+ `DOCKER_HOST`, then the active Docker context (`DOCKER_CONTEXT`, then
44
+ `currentContext` in `~/.docker/config.json`), falling back to the platform's
45
+ default socket. TLS material comes from `DOCKER_CERT_PATH` and
46
+ `DOCKER_TLS_VERIFY`, or from the context itself.
47
+
48
+ ```ruby
49
+ client = Docker::API::Client.new
50
+
51
+ client = Docker::API::Client.new(url: "unix:///var/run/docker.sock")
52
+ client = Docker::API::Client.new(url: "npipe:////./pipe/docker_engine") # Windows
53
+ client = Docker::API::Client.new(
54
+ url: "tcp://build.internal:2376",
55
+ tls: { ca_file: "ca.pem", cert_file: "cert.pem", key_file: "key.pem" }
56
+ )
57
+ ```
58
+
59
+ A client owns its configuration and its connection, and there is no global
60
+ state behind it. Two clients talking to two daemons share nothing:
61
+
62
+ ```ruby
63
+ local = Docker::API::Client.new
64
+ build = Docker::API::Client.new(url: "tcp://build.internal:2376")
65
+ ```
66
+
67
+ See [docs/connecting.md](docs/connecting.md) for version negotiation, timeouts,
68
+ logging and TLS in detail.
69
+
70
+ ## Containers
71
+
72
+ ```ruby
73
+ client.containers.all(all: true) # => [Container]
74
+ client.containers.get("web") # => Container, raises NotFound
75
+ client.containers.find("web") # => Container or nil
76
+
77
+ container = client.containers.create(
78
+ image: "alpine:3.20",
79
+ name: "worker",
80
+ cmd: %w{sleep 3600},
81
+ env: ["LOG_LEVEL=debug"],
82
+ host_config: { "Binds" => ["/data:/data:ro"] }
83
+ )
84
+
85
+ container.start
86
+ container.stop(timeout: 10)
87
+ container.remove(force: true, volumes: true)
88
+ ```
89
+
90
+ Body attributes may be written in snake_case and are translated to the daemon's
91
+ spelling. Keys already in Docker's convention pass through untouched, so a
92
+ configuration copied out of Docker's documentation works as-is.
93
+
94
+ ### Resources answer the same question the same way
95
+
96
+ `GET /containers/json` reports `Names: ["/web"]`. `GET /containers/{id}/json`
97
+ reports `Name: "/web"`. Resources here normalise that, so code does not have to
98
+ know which call produced the object it is holding:
99
+
100
+ ```ruby
101
+ listed = client.containers.all.first # from a list
102
+ inspected = client.containers.get("web") # from an inspect
103
+
104
+ listed.name == inspected.name # => true
105
+ listed.state == inspected.state # => true
106
+ listed.ports == inspected.ports # => true
107
+ ```
108
+
109
+ An object built from a list marks itself `partial?`. The first accessor that
110
+ needs detail the list did not carry fetches it once, rather than returning nil
111
+ and leaving you to guess why. The untouched payload is always available as
112
+ `#raw`.
113
+
114
+ ## Running commands
115
+
116
+ ```ruby
117
+ result = container.exec(%w{chef-client -z}, env: { "TERM" => "xterm" }) do |stream, chunk|
118
+ logger << chunk if stream == :stdout
119
+ end
120
+
121
+ result.stdout
122
+ result.stderr
123
+ result.exit_code
124
+ result.success?
125
+ ```
126
+
127
+ Without a TTY the daemon multiplexes both streams down one connection with an
128
+ eight-byte frame header. That is decoded for you, so `:stdout` and `:stderr`
129
+ arrive separately instead of interleaved. A non-zero exit is returned rather
130
+ than raised — whether a failing command is an error depends on why you ran it.
131
+ Use `result.check!` when it is.
132
+
133
+ ## Images
134
+
135
+ ```ruby
136
+ client.images.pull("alpine:3.20", platform: "linux/arm64") { |event| puts event["status"] }
137
+ client.images.build(context: "./app", tag: "app:dev") { |event| print event["stream"] }
138
+ client.images.build(dockerfile: "FROM alpine\nRUN apk add curl\n", tag: "curl:dev")
139
+ client.images.ensure("alpine:3.20") # pull only if absent
140
+ ```
141
+
142
+ Registry credentials are resolved per call from `~/.docker/config.json`,
143
+ including `credsStore` and `credHelpers`, so pulling from two private
144
+ registries in one process needs no setup between calls.
145
+
146
+ ## Networks and volumes
147
+
148
+ ```ruby
149
+ network = client.networks.ensure("dokken", ipv6: true)
150
+ network.connect(container, aliases: %w{web})
151
+ network.disconnect(container)
152
+
153
+ volume = client.volumes.create("cache", labels: { "team" => "infra" })
154
+ volume.remove
155
+ ```
156
+
157
+ `ensure` treats losing a creation race as success, because two processes
158
+ racing to create the same shared network is ordinary rather than exceptional.
159
+
160
+ ## The daemon itself
161
+
162
+ ```ruby
163
+ client.system.info
164
+ client.system.version
165
+ client.system.ping? # => true / false, never raises
166
+ client.system.podman? # Podman wearing Docker's API
167
+ client.system.rootless?
168
+
169
+ client.system.events(filters: { "type" => ["container"] }) do |event|
170
+ puts "#{event["Action"]} #{event.dig("Actor", "Attributes", "name")}"
171
+ end
172
+ ```
173
+
174
+ ## Everything else
175
+
176
+ The generated layer is public API, not an escape hatch. Every one of the 108
177
+ Engine API operations is there, documented, typed, and named after the
178
+ specification's own `operationId`:
179
+
180
+ ```ruby
181
+ client.operations.container_prune(filters: { "until" => ["24h"] })
182
+ client.operations.swarm_init(body: { "ListenAddr" => "0.0.0.0:2377" })
183
+ client.operations.service_list(filters: { "name" => ["web"] })
184
+ client.operations.node_list
185
+ client.operations.secret_create(body: { "Name" => "token", "Data" => encoded })
186
+ client.operations.plugin_list
187
+ ```
188
+
189
+ The ergonomic collections above cover what most code reaches for. Anything they
190
+ have not grown sugar for is reachable here with no loss of capability, and the
191
+ list of ergonomic wrappers grows over time without ever being a coverage
192
+ bottleneck.
193
+
194
+ ## Errors
195
+
196
+ Everything this gem raises descends from `Docker::API::Error`, and nothing from
197
+ beneath the abstraction escapes — no `Errno`, no `OpenSSL`, no `Net::` class
198
+ reaches your rescue clause. The original is always kept as `#cause`.
199
+
200
+ ```ruby
201
+ begin
202
+ client.containers.get("missing")
203
+ rescue Docker::API::NotFound => e
204
+ e.operation #=> "container_inspect"
205
+ e.status #=> 404
206
+ e.message #=> "container_inspect failed (HTTP 404): No such container: missing"
207
+ rescue Docker::API::ConnectionError => e
208
+ e.cause #=> #<Errno::ENOENT ...>
209
+ end
210
+ ```
211
+
212
+ See [docs/errors.md](docs/errors.md) for the full hierarchy.
213
+
214
+ ## Testing code that uses this gem
215
+
216
+ `Docker::API::Transport::Fake` scripts a daemon over a real socket pair, so
217
+ tests exercise the actual request path with no network and no daemon:
218
+
219
+ ```ruby
220
+ fake = Docker::API::Transport::Fake.new([
221
+ "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 26\r\n\r\n" \
222
+ '{"Id":"abc","Name":"/web"}',
223
+ ])
224
+ client = Docker::API::Client.new(transport: fake, api_version: "1.55")
225
+
226
+ client.containers.get("web").name #=> "web"
227
+ fake.requests.first #=> "GET /v1.55/containers/web/json HTTP/1.1\r\n..."
228
+ ```
229
+
230
+ The socket is genuine on purpose: `Net::BufferedIO` calls `read_nonblock`,
231
+ `write` and `to_io` on whatever it is handed, and a StringIO does not honour
232
+ that contract. Faking it produces tests that pass against something the real
233
+ code could never drive.
234
+
235
+ ## How it stays current
236
+
237
+ The API surface is generated from `data/swagger/v1.55.yaml`, a vendored copy of
238
+ Docker's own specification:
239
+
240
+ ```console
241
+ $ bundle exec rake api:sync[1.56] # fetch a newer spec and regenerate
242
+ $ git diff --stat # review what changed
243
+ ```
244
+
245
+ A new endpoint appears as a new method. A removed parameter vanishes from the
246
+ signature and the type checker names every caller that still passes it.
247
+ Generated files are committed, so installing the gem needs no toolchain, and
248
+ upgrading the supported API version is a pull request somebody reads.
249
+
250
+ See [docs/extending.md](docs/extending.md).
251
+
252
+ ## Documentation
253
+
254
+ | Guide | What it covers |
255
+ | --- | --- |
256
+ | [Connecting](docs/connecting.md) | URLs, TLS, named pipes, version negotiation, timeouts, logging |
257
+ | [Errors](docs/errors.md) | The hierarchy, what each one means, retrying |
258
+ | [Running commands](docs/exec.md) | exec, attach, logs, stream multiplexing |
259
+ | [Building images](docs/building-images.md) | Build contexts, .dockerignore, build args, registries |
260
+ | [Streaming](docs/streaming.md) | The three wire formats and how they are decoded |
261
+ | [Extending](docs/extending.md) | The generator, adding ergonomics, upgrading the API version |
262
+ | [Migrating from docker-api](docs/migrating-from-docker-api.md) | A call-by-call table |
263
+
264
+ ## Relationship to the docker-api gem
265
+
266
+ This is not a fork and keeps no compatibility with
267
+ [docker-api](https://github.com/upserve/docker-api). It was written because a
268
+ few of that gem's design decisions are difficult to work around from outside:
269
+ process-global connection and credential state, hand-transcribed parameters
270
+ that silently drop what they miss, `Excon` exceptions reaching callers, and no
271
+ Windows named pipe support.
272
+
273
+ Everything here lives under `Docker::API` and nothing is added to `::Docker`,
274
+ so both gems can be loaded into one process while a migration is in progress.
275
+
276
+ ## Licence
277
+
278
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/docker/api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "docker-api-ng"
7
+ spec.version = Docker::API::VERSION
8
+ spec.authors = ["Tim Smith"]
9
+ spec.email = ["tsmith84@proton.me"]
10
+ spec.summary = "A Ruby client for the modern Docker Engine API"
11
+ spec.description = <<~DESC
12
+ A dependency-free Ruby client for the Docker Engine API. The complete API
13
+ surface is generated from Docker's own OpenAPI specification, so keeping up
14
+ with the daemon is a reviewable diff rather than manual archaeology, and an
15
+ ergonomic hand-written layer sits on top of it.
16
+ DESC
17
+ spec.homepage = "https://github.com/test-kitchen/docker-api-ng"
18
+ spec.license = "Apache-2.0"
19
+
20
+ spec.metadata = {
21
+ "bug_tracker_uri" => "#{spec.homepage}/issues",
22
+ "changelog_uri" => "#{spec.homepage}/blob/main/CHANGELOG.md",
23
+ "documentation_uri" => "#{spec.homepage}/blob/main/README.md",
24
+ "source_code_uri" => spec.homepage,
25
+ }
26
+
27
+ spec.required_ruby_version = ">= 3.1"
28
+
29
+ # data/swagger/*.yaml is deliberately not packaged. It is a build-time input:
30
+ # `rake api:generate` reads it to emit lib/docker/api/operations.rb, which is
31
+ # committed. Nothing loads the specification at runtime, and the generator
32
+ # that consumes it lives in tools/, which is not shipped either -- so packaging
33
+ # it added 471 KB, about four fifths of the gem, that no installed copy can
34
+ # use. It stays in the repository, where the generator and reviewers want it.
35
+ spec.files = %w{LICENSE NOTICE README.md docker-api-ng.gemspec} +
36
+ Dir.glob("lib/**/*.rb") +
37
+ Dir.glob("sig/**/*.rbs") +
38
+ Dir.glob("docs/*.md")
39
+ spec.require_paths = ["lib"]
40
+
41
+ # No runtime dependencies. Everything this gem needs ships with Ruby.
42
+ end
@@ -0,0 +1,98 @@
1
+ # Building images
2
+
3
+ ## From a directory
4
+
5
+ ```ruby
6
+ image = client.images.build(context: "./app", tag: "app:dev") do |event|
7
+ print event["stream"] if event["stream"]
8
+ end
9
+ ```
10
+
11
+ The directory is packed into a tar archive with `Gem::Package::TarWriter`,
12
+ which ships with Ruby — no dependency, no shelling out to `tar`, and identical
13
+ behaviour on Windows where there may be no `tar` to shell out to.
14
+
15
+ `.dockerignore` is honoured, including `!` negations, where the last matching
16
+ rule wins.
17
+
18
+ ## From a Dockerfile in memory
19
+
20
+ For a short generated build with no accompanying files, writing a temporary
21
+ directory first is ceremony for its own sake:
22
+
23
+ ```ruby
24
+ client.images.build(
25
+ dockerfile: <<~DOCKERFILE,
26
+ FROM alpine:3.20
27
+ RUN apk add --no-cache curl
28
+ DOCKERFILE
29
+ tag: "curl:dev"
30
+ )
31
+ ```
32
+
33
+ ## Options
34
+
35
+ ```ruby
36
+ client.images.build(
37
+ context: "./app",
38
+ dockerfile: "Dockerfile.ci", # a path within the context
39
+ tag: "app:ci",
40
+ platform: "linux/arm64",
41
+ buildargs: { "VERSION" => "2026.08" },
42
+ labels: { "team" => "infra" },
43
+ target: "runtime", # stop at a multi-stage stage
44
+ nocache: true,
45
+ pull: true,
46
+ rm: true
47
+ )
48
+ ```
49
+
50
+ ## Build failures
51
+
52
+ The daemon reports a failed build inside a `200` response, as an `error` key in
53
+ the JSON-lines stream. Anything that only checks the HTTP status concludes the
54
+ build succeeded and then fails confusingly later.
55
+
56
+ `build` reads the stream and raises:
57
+
58
+ ```ruby
59
+ begin
60
+ client.images.build(context: ".", tag: "app:dev")
61
+ rescue Docker::API::Error => e
62
+ e.message #=> "image build failed: The command '/bin/sh -c apk add nope' returned a non-zero code: 1"
63
+ end
64
+ ```
65
+
66
+ ## Pulling
67
+
68
+ ```ruby
69
+ client.images.pull("alpine:3.20")
70
+ client.images.pull("ghcr.io/team/app:1.0", platform: "linux/arm64")
71
+ client.images.ensure("alpine:3.20") # pull only if it is not already here
72
+ ```
73
+
74
+ Credentials are resolved for the registry in the reference, from
75
+ `~/.docker/config.json`, including `credsStore` and `credHelpers`. Every
76
+ failure in that lookup is soft: a missing config file, an unreadable one, or an
77
+ uninstalled helper all mean "no credentials", because anonymous pulls of public
78
+ images must keep working on a machine that has never run `docker login`.
79
+
80
+ Pass `auth:` to override:
81
+
82
+ ```ruby
83
+ credentials = Docker::API::Auth.encode(
84
+ username: "token", password: ENV.fetch("REGISTRY_TOKEN"), serveraddress: "ghcr.io"
85
+ )
86
+ client.images.pull("ghcr.io/team/app:1.0", auth: credentials)
87
+ ```
88
+
89
+ ## A note on `platform`
90
+
91
+ The Engine API asks for platforms in two incompatible encodings depending on
92
+ the endpoint. Build, pull and container-create want the string
93
+ `"linux/arm64"`; inspect, push, history and save want a JSON-encoded OCI
94
+ object. Sending the wrong one fails with
95
+ `400 failed to parse platform: invalid character 'l'`.
96
+
97
+ Write `"linux/arm64"` everywhere. `Docker::API::Platform` encodes whichever
98
+ form the endpoint in question wants.