Class: Docker::API::Container
Overview
This class represents the Docker API endpoints regarding containers.
Instance Method Summary collapse
-
#attach(name, params = {}, &block) ⇒ Object
Attach to a container.
-
#changes(name) ⇒ Object
Get changes on a container’s filesystem.
-
#create(params = {}, body = {}) ⇒ Object
Create a container.
-
#details(name, params = {}) ⇒ Object
Return low-level information about a container.
-
#export(name, path, &block) ⇒ Object
Export the contents of a container as a tarball.
-
#get_archive(name, path, params = {}, &block) ⇒ Object
Get an archive of a filesystem resource in a container.
-
#kill(name, params = {}) ⇒ Object
Send a POSIX signal to a container, defaulting to killing to the container.
-
#list(params = {}) ⇒ Object
Return a list of containers.
-
#logs(name, params = {}, &block) ⇒ Object
Get stdout and stderr logs from a container.
-
#pause(name) ⇒ Object
Pause a container.
-
#prune(params = {}) ⇒ Object
Delete stopped containers.
-
#put_archive(name, path, params = {}) ⇒ Object
Extract an archive of files or folders to a directory in a container.
-
#remove(name, params = {}) ⇒ Object
Remove a container.
-
#rename(name, params = {}) ⇒ Object
Rename a container.
-
#resize(name, params = {}) ⇒ Object
Resize the TTY for a container.
-
#restart(name, params = {}) ⇒ Object
Restart a container.
-
#start(name, params = {}) ⇒ Object
Start a container.
-
#stats(name, params = {}, &block) ⇒ Object
Get container stats based on resource usage.
-
#stop(name, params = {}) ⇒ Object
Stop a container.
-
#top(name, params = {}) ⇒ Object
List processes running inside a container.
-
#unpause(name) ⇒ Object
Resume a container which has been paused.
-
#update(name, body = {}) ⇒ Object
Change various configuration options of a container without having to recreate it.
-
#wait(name, params = {}) ⇒ Object
Block until a container stops, then returns the exit code.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Docker::API::Base
Instance Method Details
#attach(name, params = {}, &block) ⇒ Object
Attach to a container.
Docker API: POST /containers/id/attach
222 223 224 |
# File 'lib/docker/api/container.rb', line 222 def attach name, params = {}, &block @connection.request(method: :post, path: build_path("/containers/#{name}/attach", params) , response_block: block_given? ? block : default_streamer) end |
#changes(name) ⇒ Object
Get changes on a container’s filesystem.
Docker API: GET /containers/id/changes
48 49 50 |
# File 'lib/docker/api/container.rb', line 48 def changes name @connection.get("/containers/#{name}/changes") end |
#create(params = {}, body = {}) ⇒ Object
Create a container.
Docker API: POST /containers/create
234 235 236 |
# File 'lib/docker/api/container.rb', line 234 def create params = {}, body = {} @connection.request(method: :post, path: build_path("/containers/create", params), headers: {"Content-Type": "application/json"}, body: body.to_json) end |
#details(name, params = {}) ⇒ Object
Return low-level information about a container.
Docker API: GET /containers/id/json
25 26 27 |
# File 'lib/docker/api/container.rb', line 25 def details name, params = {} @connection.get(build_path("/containers/#{name}/json", params)) end |
#export(name, path, &block) ⇒ Object
Export the contents of a container as a tarball.
Docker API: GET /containers/id/export
265 266 267 268 269 |
# File 'lib/docker/api/container.rb', line 265 def export name, path, &block response = self.details(name) return response unless response.status == 200 @connection.request(method: :get, path: "/containers/#{name}/export" , response_block: block_given? ? block : default_writer(path)) end |
#get_archive(name, path, params = {}, &block) ⇒ Object
Get an archive of a filesystem resource in a container.
Get a tar archive of a resource in the filesystem of container id.
Docker API: GET /containers/id/archive
283 284 285 286 287 288 289 290 291 |
# File 'lib/docker/api/container.rb', line 283 def get_archive name, path, params = {}, &block response = @connection.head(build_path("/containers/#{name}/archive", params)) return response unless response.status == 200 file = File.open( File.( path ) , "wb") 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) }) file.close response end |
#kill(name, params = {}) ⇒ Object
Send a POSIX signal to a container, defaulting to killing to the container.
Docker API: POST /containers/id/kill
96 97 98 |
# File 'lib/docker/api/container.rb', line 96 def kill name, params = {} @connection.post(build_path("/containers/#{name}/kill", params)) end |
#list(params = {}) ⇒ Object
Return a list of containers.
Docker API: GET /containers/json
13 14 15 |
# File 'lib/docker/api/container.rb', line 13 def list params = {} @connection.get(build_path("/containers/json", params)) end |
#logs(name, params = {}, &block) ⇒ Object
Get stdout and stderr logs from a container.
Docker API: GET /containers/id/logs
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/docker/api/container.rb', line 202 def logs name, params = {}, &block path = build_path("/containers/#{name}/logs", params) if [true, 1 ].include? params[:follow] @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer) else @connection.get(path) end end |
#pause(name) ⇒ Object
Pause a container.
Docker API: POST /containers/id/pause
166 167 168 |
# File 'lib/docker/api/container.rb', line 166 def pause name @connection.post("/containers/#{name}/pause") end |
#prune(params = {}) ⇒ Object
Delete stopped containers.
Docker API: POST /containers/prune
155 156 157 |
# File 'lib/docker/api/container.rb', line 155 def prune params = {} @connection.post(build_path("/containers/prune", params)) end |
#put_archive(name, path, params = {}) ⇒ Object
Extract an archive of files or folders to a directory in a container.
Upload a tar archive to be extracted to a path in the filesystem of container id.
Docker API: PUT /containers/id/archive
304 305 306 307 308 309 |
# File 'lib/docker/api/container.rb', line 304 def put_archive name, path, params = {} file = File.open( File.( path ) , "r") response = @connection.request(method: :put, path: build_path("/containers/#{name}/archive", params) , request_block: lambda { file.read(Excon.defaults[:chunk_size]).to_s} ) file.close response end |
#remove(name, params = {}) ⇒ Object
Remove a container.
Docker API: DELETE /containers/id
189 190 191 |
# File 'lib/docker/api/container.rb', line 189 def remove name, params = {} @connection.delete(build_path("/containers/#{name}", params)) end |
#rename(name, params = {}) ⇒ Object
Rename a container.
Docker API: POST /containers/id/rename
132 133 134 |
# File 'lib/docker/api/container.rb', line 132 def rename name, params = {} @connection.post(build_path("/containers/#{name}/rename", params)) end |
#resize(name, params = {}) ⇒ Object
Resize the TTY for a container.
Docker API: POST /containers/id/resize
144 145 146 |
# File 'lib/docker/api/container.rb', line 144 def resize name, params = {} @connection.post(build_path("/containers/#{name}/resize", params)) end |
#restart(name, params = {}) ⇒ Object
Restart a container.
Docker API: POST /containers/id/restart
84 85 86 |
# File 'lib/docker/api/container.rb', line 84 def restart name, params = {} @connection.post(build_path("/containers/#{name}/restart", params)) end |
#start(name, params = {}) ⇒ Object
Start a container.
Docker API: POST /containers/id/start
60 61 62 |
# File 'lib/docker/api/container.rb', line 60 def start name, params = {} @connection.post(build_path("/containers/#{name}/start", params)) end |
#stats(name, params = {}, &block) ⇒ Object
Get container stats based on resource usage.
Docker API: GET /containers/id/stats
247 248 249 250 251 252 253 254 |
# File 'lib/docker/api/container.rb', line 247 def stats name, params = {}, &block path = build_path("/containers/#{name}/stats", params) if [true, 1 ].include? params[:stream] @connection.request(method: :get, path: path , response_block: block_given? ? block : default_streamer) else @connection.get(path) end end |
#stop(name, params = {}) ⇒ Object
Stop a container.
Docker API: POST /containers/id/stop
72 73 74 |
# File 'lib/docker/api/container.rb', line 72 def stop name, params = {} @connection.post(build_path("/containers/#{name}/stop", params)) end |
#top(name, params = {}) ⇒ Object
List processes running inside a container.
Docker API: GET /containers/id/top
37 38 39 |
# File 'lib/docker/api/container.rb', line 37 def top name, params = {} @connection.get(build_path("/containers/#{name}/top", params)) end |
#unpause(name) ⇒ Object
Resume a container which has been paused.
Docker API: POST /containers/id/unpause
177 178 179 |
# File 'lib/docker/api/container.rb', line 177 def unpause name @connection.post("/containers/#{name}/unpause") end |
#update(name, body = {}) ⇒ Object
Change various configuration options of a container without having to recreate it.
Docker API: POST /containers/id/update
120 121 122 |
# File 'lib/docker/api/container.rb', line 120 def update name, body = {} @connection.request(method: :post, path: "/containers/#{name}/update", headers: {"Content-Type": "application/json"}, body: body.to_json) end |
#wait(name, params = {}) ⇒ Object
Block until a container stops, then returns the exit code.
Docker API: POST /containers/id/wait
108 109 110 |
# File 'lib/docker/api/container.rb', line 108 def wait name, params = {} @connection.post(build_path("/containers/#{name}/wait", params)) end |