Class: DockerEngineRuby::Resources::Containers

Inherits:
Object
  • Object
show all
Defined in:
lib/docker_engine_ruby/resources/containers.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Containers

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Containers.

Parameters:



623
624
625
# File 'lib/docker_engine_ruby/resources/containers.rb', line 623

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(id, path:, request_options: {}) ⇒ nil

Get an archive of a filesystem resource in a container

Parameters:

Returns:

  • (nil)

See Also:



180
181
182
183
184
185
186
187
188
189
190
# File 'lib/docker_engine_ruby/resources/containers.rb', line 180

def archive(id, params)
  parsed, options = DockerEngineRuby::ContainerArchiveParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["containers/%1$s/archive", id],
    query: query,
    model: NilClass,
    options: options
  )
end

#attach(id, detach_keys: nil, logs: nil, stderr: nil, stdin: nil, stdout: nil, stream: nil, request_options: {}) ⇒ nil

Attach to a container

Parameters:

  • id (String)
  • detach_keys (String)
  • logs (Boolean)
  • stderr (Boolean)
  • stdin (Boolean)
  • stdout (Boolean)
  • stream (Boolean)
  • request_options (DockerEngineRuby::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



208
209
210
211
212
213
214
215
216
217
218
# File 'lib/docker_engine_ruby/resources/containers.rb', line 208

def attach(id, params = {})
  parsed, options = DockerEngineRuby::ContainerAttachParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/attach", id],
    query: query.transform_keys(detach_keys: "detachKeys"),
    model: NilClass,
    options: options
  )
end

#changes(id, request_options: {}) ⇒ Array<DockerEngineRuby::Models::FilesystemChange>

Get changes on a container’s filesystem

Parameters:

Returns:

See Also:



230
231
232
233
234
235
236
237
# File 'lib/docker_engine_ruby/resources/containers.rb', line 230

def changes(id, params = {})
  @client.request(
    method: :get,
    path: ["containers/%1$s/changes", id],
    model: DockerEngineRuby::Internal::Type::ArrayOf[DockerEngineRuby::FilesystemChange],
    options: params[:request_options]
  )
end

#create(config:, name: nil, platform: nil, request_options: {}) ⇒ DockerEngineRuby::Models::CreateResponse

Create a container

Parameters:

Returns:

See Also:



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/docker_engine_ruby/resources/containers.rb', line 21

def create(params)
  parsed, options = DockerEngineRuby::ContainerCreateParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed.except(:config))
  @client.request(
    method: :post,
    path: "containers/create",
    query: query,
    body: parsed[:config],
    model: DockerEngineRuby::CreateResponse,
    options: options
  )
end

#delete(id, force: nil, link: nil, v: nil, request_options: {}) ⇒ nil

Remove a container

Parameters:

Returns:

  • (nil)

See Also:



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/docker_engine_ruby/resources/containers.rb', line 157

def delete(id, params = {})
  parsed, options = DockerEngineRuby::ContainerDeleteParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :delete,
    path: ["containers/%1$s", id],
    query: query,
    model: NilClass,
    options: options
  )
end

#exec_(id, attach_stderr: nil, attach_stdin: nil, attach_stdout: nil, cmd: nil, console_size: nil, detach_keys: nil, env: nil, privileged: nil, tty: nil, user: nil, working_dir: nil, request_options: {}) ⇒ DockerEngineRuby::Models::ContainerExecResponse

Create an exec instance

Parameters:

  • id (String)
  • attach_stderr (Boolean)
  • attach_stdin (Boolean)
  • attach_stdout (Boolean)
  • cmd (Array<String>)
  • console_size (Array<Integer>, nil)
  • detach_keys (String)
  • env (Array<String>)
  • privileged (Boolean)
  • tty (Boolean)
  • user (String)
  • working_dir (String)
  • request_options (DockerEngineRuby::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



260
261
262
263
264
265
266
267
268
269
# File 'lib/docker_engine_ruby/resources/containers.rb', line 260

def exec_(id, params = {})
  parsed, options = DockerEngineRuby::ContainerExecParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["containers/%1$s/exec", id],
    body: parsed,
    model: DockerEngineRuby::Models::ContainerExecResponse,
    options: options
  )
end

#export(id, request_options: {}) ⇒ nil

Export a container

Parameters:

Returns:

  • (nil)

See Also:



281
282
283
284
285
286
287
288
# File 'lib/docker_engine_ruby/resources/containers.rb', line 281

def export(id, params = {})
  @client.request(
    method: :get,
    path: ["containers/%1$s/export", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#inspect_(id, size: nil, request_options: {}) ⇒ DockerEngineRuby::Models::Container

Inspect a container

Parameters:

Returns:

See Also:



301
302
303
304
305
306
307
308
309
310
311
# File 'lib/docker_engine_ruby/resources/containers.rb', line 301

def inspect_(id, params = {})
  parsed, options = DockerEngineRuby::ContainerInspectParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["containers/%1$s/json", id],
    query: query,
    model: DockerEngineRuby::Container,
    options: options
  )
end

#kill(id, signal: nil, request_options: {}) ⇒ nil

Kill a container

Parameters:

Returns:

  • (nil)

See Also:



324
325
326
327
328
329
330
331
332
333
334
# File 'lib/docker_engine_ruby/resources/containers.rb', line 324

def kill(id, params = {})
  parsed, options = DockerEngineRuby::ContainerKillParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/kill", id],
    query: query,
    model: NilClass,
    options: options
  )
end

#list(all: nil, filters: nil, limit: nil, size: nil, request_options: {}) ⇒ Array<DockerEngineRuby::Models::Summary>

List containers

Parameters:

Returns:

See Also:



132
133
134
135
136
137
138
139
140
141
142
# File 'lib/docker_engine_ruby/resources/containers.rb', line 132

def list(params = {})
  parsed, options = DockerEngineRuby::ContainerListParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "containers/json",
    query: query,
    model: DockerEngineRuby::Internal::Type::ArrayOf[DockerEngineRuby::Summary],
    options: options
  )
end

#logs(id, follow: nil, since: nil, stderr: nil, stdout: nil, tail: nil, timestamps: nil, until_: nil, request_options: {}) ⇒ StringIO

Get container logs

Parameters:

  • id (String)
  • follow (Boolean)
  • since (Integer)
  • stderr (Boolean)
  • stdout (Boolean)
  • tail (String)
  • timestamps (Boolean)
  • until_ (Integer)
  • request_options (DockerEngineRuby::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (StringIO)

See Also:



353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/docker_engine_ruby/resources/containers.rb', line 353

def logs(id, params = {})
  parsed, options = DockerEngineRuby::ContainerLogsParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["containers/%1$s/logs", id],
    query: query.transform_keys(until_: "until"),
    headers: {"accept" => "application/octet-stream"},
    model: StringIO,
    options: options
  )
end

#pause(id, request_options: {}) ⇒ nil

Pause a container

Parameters:

Returns:

  • (nil)

See Also:



376
377
378
379
380
381
382
383
# File 'lib/docker_engine_ruby/resources/containers.rb', line 376

def pause(id, params = {})
  @client.request(
    method: :post,
    path: ["containers/%1$s/pause", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#prune(filters: nil, request_options: {}) ⇒ DockerEngineRuby::Models::ContainerPruneResponse

Delete stopped containers

Parameters:

Returns:

See Also:



395
396
397
398
399
400
401
402
403
404
405
# File 'lib/docker_engine_ruby/resources/containers.rb', line 395

def prune(params = {})
  parsed, options = DockerEngineRuby::ContainerPruneParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: "containers/prune",
    query: query,
    model: DockerEngineRuby::Models::ContainerPruneResponse,
    options: options
  )
end

#rename(id, name:, request_options: {}) ⇒ nil

Rename a container

Parameters:

Returns:

  • (nil)

See Also:



418
419
420
421
422
423
424
425
426
427
428
# File 'lib/docker_engine_ruby/resources/containers.rb', line 418

def rename(id, params)
  parsed, options = DockerEngineRuby::ContainerRenameParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/rename", id],
    query: query,
    model: NilClass,
    options: options
  )
end

#resize(id, h:, w:, request_options: {}) ⇒ nil

Resize a container TTY

Parameters:

Returns:

  • (nil)

See Also:



442
443
444
445
446
447
448
449
450
451
452
# File 'lib/docker_engine_ruby/resources/containers.rb', line 442

def resize(id, params)
  parsed, options = DockerEngineRuby::ContainerResizeParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/resize", id],
    query: query,
    model: NilClass,
    options: options
  )
end

#restart(id, signal: nil, t: nil, request_options: {}) ⇒ nil

Restart a container

Parameters:

Returns:

  • (nil)

See Also:



466
467
468
469
470
471
472
473
474
475
476
# File 'lib/docker_engine_ruby/resources/containers.rb', line 466

def restart(id, params = {})
  parsed, options = DockerEngineRuby::ContainerRestartParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/restart", id],
    query: query,
    model: NilClass,
    options: options
  )
end

#start(id, detach_keys: nil, request_options: {}) ⇒ nil

Start a container

Parameters:

Returns:

  • (nil)

See Also:



489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/docker_engine_ruby/resources/containers.rb', line 489

def start(id, params = {})
  parsed, options = DockerEngineRuby::ContainerStartParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/start", id],
    query: query.transform_keys(detach_keys: "detachKeys"),
    model: NilClass,
    options: options
  )
rescue DockerEngineRuby::Errors::APIStatusError => e
  raise e unless e.status == 304
  nil
end

#stats(id, one_shot: nil, stream: nil, request_options: {}) ⇒ DockerEngineRuby::Models::StatsResponse

Get container stats based on resource usage

Parameters:

Returns:

See Also:



516
517
518
519
520
521
522
523
524
525
526
# File 'lib/docker_engine_ruby/resources/containers.rb', line 516

def stats(id, params = {})
  parsed, options = DockerEngineRuby::ContainerStatsParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["containers/%1$s/stats", id],
    query: query.transform_keys(one_shot: "one-shot"),
    model: DockerEngineRuby::StatsResponse,
    options: options
  )
end

#stop(id, signal: nil, t: nil, request_options: {}) ⇒ nil

Stop a container

Parameters:

Returns:

  • (nil)

See Also:



540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/docker_engine_ruby/resources/containers.rb', line 540

def stop(id, params = {})
  parsed, options = DockerEngineRuby::ContainerStopParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/stop", id],
    query: query,
    model: NilClass,
    options: options
  )
rescue DockerEngineRuby::Errors::APIStatusError => e
  raise e unless e.status == 304
  nil
end

#top(id, ps_args: nil, request_options: {}) ⇒ DockerEngineRuby::Models::TopResponse

List processes running inside a container

Parameters:

Returns:

See Also:



566
567
568
569
570
571
572
573
574
575
576
# File 'lib/docker_engine_ruby/resources/containers.rb', line 566

def top(id, params = {})
  parsed, options = DockerEngineRuby::ContainerTopParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["containers/%1$s/top", id],
    query: query,
    model: DockerEngineRuby::TopResponse,
    options: options
  )
end

#unpause(id, request_options: {}) ⇒ nil

Unpause a container

Parameters:

Returns:

  • (nil)

See Also:



588
589
590
591
592
593
594
595
# File 'lib/docker_engine_ruby/resources/containers.rb', line 588

def unpause(id, params = {})
  @client.request(
    method: :post,
    path: ["containers/%1$s/unpause", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#update(id, blkio_device_read_bps: nil, blkio_device_read_i_ops: nil, blkio_device_write_bps: nil, blkio_device_write_i_ops: nil, blkio_weight: nil, blkio_weight_device: nil, cgroup_parent: nil, cpu_count: nil, cpu_percent: nil, cpu_period: nil, cpu_quota: nil, cpu_realtime_period: nil, cpu_realtime_runtime: nil, cpuset_cpus: nil, cpuset_mems: nil, cpu_shares: nil, device_cgroup_rules: nil, device_requests: nil, devices: nil, init: nil, io_maximum_bandwidth: nil, io_maximum_i_ops: nil, memory: nil, memory_reservation: nil, memory_swap: nil, memory_swappiness: nil, nano_cpus: nil, oom_kill_disable: nil, pids_limit: nil, ulimits: nil, request_options: {}) ⇒ DockerEngineRuby::Models::UpdateResponse

Some parameter documentations has been truncated, see Models::ContainerUpdateParams for more details.

Update a container

Parameters:

  • id (String)
  • blkio_device_read_bps (Array<DockerEngineRuby::Models::ContainerUpdateParams::BlkioDeviceReadBp>)

    Limit read rate (bytes per second) from a device, in the form:

  • blkio_device_read_i_ops (Array<DockerEngineRuby::Models::ContainerUpdateParams::BlkioDeviceReadIOp>)

    Limit read rate (IO per second) from a device, in the form:

  • blkio_device_write_bps (Array<DockerEngineRuby::Models::ContainerUpdateParams::BlkioDeviceWriteBp>)

    Limit write rate (bytes per second) to a device, in the form:

  • blkio_device_write_i_ops (Array<DockerEngineRuby::Models::ContainerUpdateParams::BlkioDeviceWriteIOp>)

    Limit write rate (IO per second) to a device, in the form:

  • blkio_weight (Integer)

    Block IO weight (relative weight).

  • blkio_weight_device (Array<DockerEngineRuby::Models::ContainerUpdateParams::BlkioWeightDevice>)

    Block IO weight (relative device weight) in the form:

  • cgroup_parent (String)

    Path to ‘cgroups` under which the container’s ‘cgroup` is created. If

  • cpu_count (Integer)

    The number of usable CPUs (Windows only).

  • cpu_percent (Integer)

    The usable percentage of the available CPUs (Windows only).

  • cpu_period (Integer)

    The length of a CPU period in microseconds.

  • cpu_quota (Integer)

    Microseconds of CPU time that the container can get in a CPU period.

  • cpu_realtime_period (Integer)

    The length of a CPU real-time period in microseconds. Set to 0 to

  • cpu_realtime_runtime (Integer)

    The length of a CPU real-time runtime in microseconds. Set to 0 to

  • cpuset_cpus (String)

    CPUs in which to allow execution (e.g., ‘0-3`, `0,1`).

  • cpuset_mems (String)

    Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only

  • cpu_shares (Integer)

    An integer value representing this container’s relative CPU weight

  • device_cgroup_rules (Array<String>)

    a list of cgroup rules to apply to the container

  • device_requests (Array<DockerEngineRuby::Models::ContainerUpdateParams::DeviceRequest>)

    A list of requests for devices to be sent to device drivers.

  • devices (Array<DockerEngineRuby::Models::ContainerUpdateParams::Device>)

    A list of devices to add to the container.

  • init (Boolean, nil)

    Run an init inside the container that forwards signals and reaps

  • io_maximum_bandwidth (Integer)

    Maximum IO in bytes per second for the container system drive

  • io_maximum_i_ops (Integer)

    Maximum IOps for the container system drive (Windows only)

  • memory (Integer)

    Memory limit in bytes.

  • memory_reservation (Integer)

    Memory soft limit in bytes.

  • memory_swap (Integer)

    Total memory limit (memory + swap). Set as ‘-1` to enable unlimited

  • memory_swappiness (Integer)

    Tune a container’s memory swappiness behavior. Accepts an integer

  • nano_cpus (Integer)

    CPU quota in units of 10<sup>-9</sup> CPUs.

  • oom_kill_disable (Boolean)

    Disable OOM Killer for the container.

  • pids_limit (Integer, nil)

    Tune a container’s PIDs limit. Set ‘0` or `-1` for unlimited, or `null`

  • ulimits (Array<DockerEngineRuby::Models::ContainerUpdateParams::Ulimit>)

    A list of resource limits to set in the container. For example:

  • request_options (DockerEngineRuby::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



108
109
110
111
112
113
114
115
116
117
# File 'lib/docker_engine_ruby/resources/containers.rb', line 108

def update(id, params = {})
  parsed, options = DockerEngineRuby::ContainerUpdateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["containers/%1$s/update", id],
    body: parsed,
    model: DockerEngineRuby::UpdateResponse,
    options: options
  )
end

#wait(id, condition: nil, request_options: {}) ⇒ DockerEngineRuby::Models::WaitResponse

Wait for a container

Parameters:

Returns:

See Also:



608
609
610
611
612
613
614
615
616
617
618
# File 'lib/docker_engine_ruby/resources/containers.rb', line 608

def wait(id, params = {})
  parsed, options = DockerEngineRuby::ContainerWaitParams.dump_request(params)
  query = DockerEngineRuby::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :post,
    path: ["containers/%1$s/wait", id],
    query: query,
    model: DockerEngineRuby::WaitResponse,
    options: options
  )
end