dockerapi 0.13.0 → 0.14.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 +11 -0
- data/Gemfile.lock +3 -3
- data/README.md +47 -15
- data/dockerapi.gemspec +5 -4
- data/lib/docker/api/container.rb +306 -144
- data/lib/docker/api/image.rb +19 -4
- data/lib/docker/api/version.rb +1 -1
- data/lib/dockerapi.rb +2 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac123f7f5ed500758fd1bb2a9f214495e71c6848517662eae15b92dfa00387aa
|
4
|
+
data.tar.gz: 270f7a7e14d43f73c402191f11ebf9233aa8b7e2c2e314ac3eeb2875487c5120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 878a7c0a146bc6657909151ff0e866c1b9cc93f1dc57ed6c7d0e91b87063e41496af294d1f1e7318b11b0ba3eaf03823e5e081b664b4c3bdd326d4298aed6c65
|
7
|
+
data.tar.gz: fee3d36fd9de8619fc27c588c1285c9acd6ca20a3a6ce1f9fd2ea67c807c74d90ae1a0b531ec233a227ccfd4655056e0c33e6605fa9a31040f6984ca2e3a6798
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 0.14.0
|
2
|
+
|
3
|
+
Method `Docker::API::Container#archive` is splitted in `#get_archive` and `#put_archive` as per Docker API documentation.
|
4
|
+
|
5
|
+
The following `Docker::API::Container` methods that can now receive a block:
|
6
|
+
* logs (output to stdout)
|
7
|
+
* attach (output to stdout)
|
8
|
+
* stats (output to stdout)
|
9
|
+
* export (write file)
|
10
|
+
* get_archive (write file)
|
11
|
+
|
1
12
|
# 0.13.0
|
2
13
|
|
3
14
|
Add default behavior for file read, write and output to stdout. Whenever a method can receive a block, this default behavior can be replaced.
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dockerapi (0.
|
5
|
-
excon (~> 0.
|
4
|
+
dockerapi (0.14.0)
|
5
|
+
excon (~> 0.76.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.3)
|
11
|
-
excon (0.
|
11
|
+
excon (0.76.0)
|
12
12
|
rake (12.3.3)
|
13
13
|
rspec (3.9.0)
|
14
14
|
rspec-core (~> 3.9.0)
|
data/README.md
CHANGED
@@ -1,6 +1,29 @@
|
|
1
1
|
# dockerapi
|
2
2
|
|
3
|
-
Interact
|
3
|
+
Interact with Docker API directly from Ruby code. Comprehensive implementation (all available endpoints), no local Docker installation required, easily manipulated http responses.
|
4
|
+
|
5
|
+
* [Installation](#installation)
|
6
|
+
* [Usage](#usage)
|
7
|
+
* [Images](#images)
|
8
|
+
* [Containers](#containers)
|
9
|
+
* [Volumes](#volumes)
|
10
|
+
* [Network](#network)
|
11
|
+
* [System](#system)
|
12
|
+
* [Exec](#exec)
|
13
|
+
* [Swarm](#swarm)
|
14
|
+
* [Node](#node)
|
15
|
+
* [Service](#service)
|
16
|
+
* [Task](#task)
|
17
|
+
* [Secret](#secret)
|
18
|
+
* [Config](#config)
|
19
|
+
* [Plugin](#plugin)
|
20
|
+
* [Connection](#connection)
|
21
|
+
* [Requests](#requests)
|
22
|
+
* [Response](#response)
|
23
|
+
* [Error handling](#error-handling)
|
24
|
+
* [Development](#development)
|
25
|
+
* [Contributing](#contributing)
|
26
|
+
* [License](#license)
|
4
27
|
|
5
28
|
## Installation
|
6
29
|
|
@@ -20,6 +43,12 @@ Or install it yourself as:
|
|
20
43
|
|
21
44
|
## Usage
|
22
45
|
|
46
|
+
The following section will bring you up to speed in order to use most this gem resources with pratical examples.
|
47
|
+
|
48
|
+
If you need more information about the different Docker API endpoints, please see the [Docker API documentation](https://docs.docker.com/engine/api/v1.40/).
|
49
|
+
|
50
|
+
For a more detailed and comprehensive documentation about this gem's API, please see the [documentation page](https://rubydoc.info/gems/dockerapi).
|
51
|
+
|
23
52
|
### Images
|
24
53
|
|
25
54
|
```ruby
|
@@ -151,7 +180,10 @@ container.stats("nginx", stream: true)
|
|
151
180
|
container.export("nginx", "~/exported_container")
|
152
181
|
|
153
182
|
# Get files from container
|
154
|
-
container.
|
183
|
+
container.get_archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
|
184
|
+
|
185
|
+
# Send files to container
|
186
|
+
container.put_archive("nginx", "~/html.tar", path: "/usr/share/nginx/html/")
|
155
187
|
|
156
188
|
# Stop container
|
157
189
|
container.stop("nginx")
|
@@ -510,19 +542,19 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
510
542
|
| Class | Tests | Implementation | Refactoring |
|
511
543
|
|---|---|---|---|
|
512
544
|
| Image | Ok | Ok | Ok |
|
513
|
-
| Container | Ok | Ok |
|
514
|
-
| Volume | Ok | Ok | 8/
|
515
|
-
| Network | Ok | Ok | 8/
|
516
|
-
| System | Ok | Ok | 8/
|
517
|
-
| Exec | Ok | Ok | 8/
|
518
|
-
| Swarm | Ok | Ok | 8/
|
519
|
-
| Node | Ok | Ok | 8/
|
520
|
-
| Service | Ok | Ok | 8/
|
521
|
-
| Task | Ok | Ok |
|
522
|
-
| Secret | Ok | Ok |
|
523
|
-
| Config | Ok | Ok |
|
524
|
-
| Distribution | Ok | Ok |
|
525
|
-
| Plugin | Ok | Ok |
|
545
|
+
| Container | Ok | Ok | Ok |
|
546
|
+
| Volume | Ok | Ok | 8/14 |
|
547
|
+
| Network | Ok | Ok | 8/14 |
|
548
|
+
| System | Ok | Ok | 8/14 |
|
549
|
+
| Exec | Ok | Ok | 8/14 |
|
550
|
+
| Swarm | Ok | Ok | 8/21 |
|
551
|
+
| Node | Ok | Ok | 8/21 |
|
552
|
+
| Service | Ok | Ok | 8/21 |
|
553
|
+
| Task | Ok | Ok | 8/28 |
|
554
|
+
| Secret | Ok | Ok | 8/28 |
|
555
|
+
| Config | Ok | Ok | 8/28 |
|
556
|
+
| Distribution | Ok | Ok | 8/28 |
|
557
|
+
| Plugin | Ok | Ok | 8/28 |
|
526
558
|
|
527
559
|
Add doc in these files: `base`, `connection`, `error`, `response`, `dockerapi`
|
528
560
|
|
data/dockerapi.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Alysson A. Costa"]
|
7
7
|
spec.email = ["alysson.avila.costa@gmail.com"]
|
8
8
|
|
9
|
-
spec.summary = "Interact
|
10
|
-
spec.description = "Interact
|
9
|
+
spec.summary = "Interact with Docker API from Ruby code."
|
10
|
+
spec.description = "Interact with Docker API directly from Ruby code. Comprehensive implementation (all available endpoints), no local Docker installation required, easily manipulated http responses."
|
11
11
|
spec.homepage = "https://github.com/nu12/dockerapi"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
@@ -15,15 +15,16 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = "https://github.com/nu12/dockerapi.git"
|
17
17
|
spec.metadata["changelog_uri"] = "https://github.com/nu12/dockerapi/blob/master/CHANGELOG.md"
|
18
|
+
spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/dockerapi"
|
18
19
|
|
19
20
|
# Specify which files should be added to the gem when it is released.
|
20
21
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
22
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|resources)/}) }
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|resources)/}) }
|
23
24
|
end
|
24
25
|
spec.bindir = "exe"
|
25
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
27
|
spec.require_paths = ["lib"]
|
27
28
|
|
28
|
-
spec.add_dependency("excon", "~> 0.
|
29
|
+
spec.add_dependency("excon", "~> 0.76.0")
|
29
30
|
end
|
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
|
+
# Returns 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.call : 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.call : 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.call : 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.call : 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.call : 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
|
data/lib/docker/api/image.rb
CHANGED
@@ -5,6 +5,7 @@ class Docker::API::Image < Docker::API::Base
|
|
5
5
|
|
6
6
|
##
|
7
7
|
# Return low-level information about an image.
|
8
|
+
#
|
8
9
|
# Docker API: GET /images/{name}/json
|
9
10
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageInspect
|
10
11
|
#
|
@@ -15,6 +16,7 @@ class Docker::API::Image < Docker::API::Base
|
|
15
16
|
|
16
17
|
##
|
17
18
|
# Return image digest and platform information by contacting the registry.
|
19
|
+
#
|
18
20
|
# Docker API: GET /distribution/{name}/json
|
19
21
|
# @see https://docs.docker.com/engine/api/v1.40/#tag/Distribution
|
20
22
|
#
|
@@ -25,6 +27,7 @@ class Docker::API::Image < Docker::API::Base
|
|
25
27
|
|
26
28
|
##
|
27
29
|
# Return parent layers of an image.
|
30
|
+
#
|
28
31
|
# Docker API: GET /images/{name}/history
|
29
32
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageHistory
|
30
33
|
#
|
@@ -35,6 +38,7 @@ class Docker::API::Image < Docker::API::Base
|
|
35
38
|
|
36
39
|
##
|
37
40
|
# Returns a list of images on the server. Note that it uses a different, smaller representation of an image than inspecting a single image.
|
41
|
+
#
|
38
42
|
# Docker API: GET /images/json
|
39
43
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageList
|
40
44
|
#
|
@@ -45,6 +49,7 @@ class Docker::API::Image < Docker::API::Base
|
|
45
49
|
|
46
50
|
##
|
47
51
|
# Search for an image on Docker Hub.
|
52
|
+
#
|
48
53
|
# Docker API: GET /images/search
|
49
54
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageSearch
|
50
55
|
#
|
@@ -55,6 +60,7 @@ class Docker::API::Image < Docker::API::Base
|
|
55
60
|
|
56
61
|
##
|
57
62
|
# Tag an image so that it becomes part of a repository.
|
63
|
+
#
|
58
64
|
# Docker API: POST /images/{name}/tag
|
59
65
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageTag
|
60
66
|
#
|
@@ -66,6 +72,7 @@ class Docker::API::Image < Docker::API::Base
|
|
66
72
|
|
67
73
|
##
|
68
74
|
# Delete unused images.
|
75
|
+
#
|
69
76
|
# Docker API: POST /images/prune
|
70
77
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImagePrune
|
71
78
|
#
|
@@ -76,7 +83,9 @@ class Docker::API::Image < Docker::API::Base
|
|
76
83
|
|
77
84
|
##
|
78
85
|
# Remove an image, along with any untagged parent images that were referenced by that image.
|
86
|
+
#
|
79
87
|
# Images can't be removed if they have descendant images, are being used by a running container or are being used by a build.
|
88
|
+
#
|
80
89
|
# Docker API: DELETE /images/{name}
|
81
90
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageDelete
|
82
91
|
#
|
@@ -88,19 +97,20 @@ class Docker::API::Image < Docker::API::Base
|
|
88
97
|
|
89
98
|
##
|
90
99
|
# Export an image.
|
100
|
+
#
|
91
101
|
# Docker API: GET /images/{name}/get
|
92
102
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageGet
|
93
103
|
#
|
94
104
|
# @param name [String]: The ID or name of the image.
|
95
|
-
# @param path [
|
96
|
-
# @param block
|
97
|
-
|
98
|
-
def export name, path = "exported_image", &block
|
105
|
+
# @param path [String]: Path to the exported file.
|
106
|
+
# @param &block: Replace the default file writing behavior.
|
107
|
+
def export name, path, &block
|
99
108
|
@connection.request(method: :get, path: build_path("/images/#{name}/get") , response_block: block_given? ? block.call : default_writer(path))
|
100
109
|
end
|
101
110
|
|
102
111
|
##
|
103
112
|
# Import images.
|
113
|
+
#
|
104
114
|
# Docker API: POST /images/load
|
105
115
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageLoad
|
106
116
|
#
|
@@ -112,6 +122,7 @@ class Docker::API::Image < Docker::API::Base
|
|
112
122
|
|
113
123
|
##
|
114
124
|
# Push an image to a registry.
|
125
|
+
#
|
115
126
|
# Docker API: POST /images/{name}/push
|
116
127
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImagePush
|
117
128
|
#
|
@@ -125,6 +136,7 @@ class Docker::API::Image < Docker::API::Base
|
|
125
136
|
|
126
137
|
##
|
127
138
|
# Create a new image from a container.
|
139
|
+
#
|
128
140
|
# Docker API: POST /commit
|
129
141
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageCommit
|
130
142
|
#
|
@@ -138,6 +150,7 @@ class Docker::API::Image < Docker::API::Base
|
|
138
150
|
|
139
151
|
##
|
140
152
|
# Create an image by either pulling it from a registry or importing it.
|
153
|
+
#
|
141
154
|
# Docker API: POST /images/create
|
142
155
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageCreate
|
143
156
|
#
|
@@ -158,6 +171,7 @@ class Docker::API::Image < Docker::API::Base
|
|
158
171
|
|
159
172
|
##
|
160
173
|
# Build an image from a tar archive with a Dockerfile in it.
|
174
|
+
#
|
161
175
|
# Docker API: POST /build
|
162
176
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/ImageBuild
|
163
177
|
#
|
@@ -180,6 +194,7 @@ class Docker::API::Image < Docker::API::Base
|
|
180
194
|
|
181
195
|
##
|
182
196
|
# Delete builder cache.
|
197
|
+
#
|
183
198
|
# Docker API: POST /build/prune
|
184
199
|
# @see https://docs.docker.com/engine/api/v1.40/#operation/BuildPrune
|
185
200
|
#
|
data/lib/docker/api/version.rb
CHANGED
data/lib/dockerapi.rb
CHANGED
@@ -57,7 +57,8 @@ module Docker
|
|
57
57
|
"logs" => [:follow, :stdout, :stderr, :since, :until, :timestamps, :tail],
|
58
58
|
"attach" => [:detachKeys, :logs, :stream, :stdin, :stdout, :stderr],
|
59
59
|
"stats" => [:stream],
|
60
|
-
"
|
60
|
+
"get_archive" => [:path],
|
61
|
+
"put_archive" => [:path, :noOverwriteDirNonDir, :copyUIDGID],
|
61
62
|
"create" => [:name]
|
62
63
|
},
|
63
64
|
"Docker::API::Volume" => {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alysson A. Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -16,15 +16,17 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.76.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
27
|
-
description: Interact
|
26
|
+
version: 0.76.0
|
27
|
+
description: Interact with Docker API directly from Ruby code. Comprehensive implementation
|
28
|
+
(all available endpoints), no local Docker installation required, easily manipulated
|
29
|
+
http responses.
|
28
30
|
email:
|
29
31
|
- alysson.avila.costa@gmail.com
|
30
32
|
executables: []
|
@@ -69,6 +71,7 @@ metadata:
|
|
69
71
|
homepage_uri: https://github.com/nu12/dockerapi
|
70
72
|
source_code_uri: https://github.com/nu12/dockerapi.git
|
71
73
|
changelog_uri: https://github.com/nu12/dockerapi/blob/master/CHANGELOG.md
|
74
|
+
documentation_uri: https://www.rubydoc.info/gems/dockerapi
|
72
75
|
post_install_message:
|
73
76
|
rdoc_options: []
|
74
77
|
require_paths:
|
@@ -87,5 +90,5 @@ requirements: []
|
|
87
90
|
rubygems_version: 3.1.2
|
88
91
|
signing_key:
|
89
92
|
specification_version: 4
|
90
|
-
summary: Interact
|
93
|
+
summary: Interact with Docker API from Ruby code.
|
91
94
|
test_files: []
|