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:



606
607
608
# File 'lib/docker_engine_ruby/resources/containers.rb', line 606

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:



177
178
179
180
181
182
183
184
185
186
# File 'lib/docker_engine_ruby/resources/containers.rb', line 177

def archive(id, params)
  parsed, options = DockerEngineRuby::ContainerArchiveParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["containers/%1$s/archive", id],
    query: parsed,
    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:



204
205
206
207
208
209
210
211
212
213
# File 'lib/docker_engine_ruby/resources/containers.rb', line 204

def attach(id, params = {})
  parsed, options = DockerEngineRuby::ContainerAttachParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["containers/%1$s/attach", id],
    query: parsed.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:



225
226
227
228
229
230
231
232
# File 'lib/docker_engine_ruby/resources/containers.rb', line 225

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
# File 'lib/docker_engine_ruby/resources/containers.rb', line 21

def create(params)
  parsed, options = DockerEngineRuby::ContainerCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "containers/create",
    query: parsed.except(:config),
    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:



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

def delete(id, params = {})
  parsed, options = DockerEngineRuby::ContainerDeleteParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["containers/%1$s", id],
    query: parsed,
    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:



255
256
257
258
259
260
261
262
263
264
# File 'lib/docker_engine_ruby/resources/containers.rb', line 255

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:



276
277
278
279
280
281
282
283
# File 'lib/docker_engine_ruby/resources/containers.rb', line 276

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:



296
297
298
299
300
301
302
303
304
305
# File 'lib/docker_engine_ruby/resources/containers.rb', line 296

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

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

Kill a container

Parameters:

Returns:

  • (nil)

See Also:



318
319
320
321
322
323
324
325
326
327
# File 'lib/docker_engine_ruby/resources/containers.rb', line 318

def kill(id, params = {})
  parsed, options = DockerEngineRuby::ContainerKillParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["containers/%1$s/kill", id],
    query: parsed,
    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:



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

def list(params = {})
  parsed, options = DockerEngineRuby::ContainerListParams.dump_request(params)
  @client.request(
    method: :get,
    path: "containers/json",
    query: parsed,
    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:



346
347
348
349
350
351
352
353
354
355
356
# File 'lib/docker_engine_ruby/resources/containers.rb', line 346

def logs(id, params = {})
  parsed, options = DockerEngineRuby::ContainerLogsParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["containers/%1$s/logs", id],
    query: parsed.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:



368
369
370
371
372
373
374
375
# File 'lib/docker_engine_ruby/resources/containers.rb', line 368

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:



387
388
389
390
391
392
393
394
395
396
# File 'lib/docker_engine_ruby/resources/containers.rb', line 387

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

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

Rename a container

Parameters:

Returns:

  • (nil)

See Also:



409
410
411
412
413
414
415
416
417
418
# File 'lib/docker_engine_ruby/resources/containers.rb', line 409

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

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

Resize a container TTY

Parameters:

Returns:

  • (nil)

See Also:



432
433
434
435
436
437
438
439
440
441
# File 'lib/docker_engine_ruby/resources/containers.rb', line 432

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

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

Restart a container

Parameters:

Returns:

  • (nil)

See Also:



455
456
457
458
459
460
461
462
463
464
# File 'lib/docker_engine_ruby/resources/containers.rb', line 455

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

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

Start a container

Parameters:

Returns:

  • (nil)

See Also:



477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/docker_engine_ruby/resources/containers.rb', line 477

def start(id, params = {})
  parsed, options = DockerEngineRuby::ContainerStartParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["containers/%1$s/start", id],
    query: parsed.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:



503
504
505
506
507
508
509
510
511
512
# File 'lib/docker_engine_ruby/resources/containers.rb', line 503

def stats(id, params = {})
  parsed, options = DockerEngineRuby::ContainerStatsParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["containers/%1$s/stats", id],
    query: parsed.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:



526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/docker_engine_ruby/resources/containers.rb', line 526

def stop(id, params = {})
  parsed, options = DockerEngineRuby::ContainerStopParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["containers/%1$s/stop", id],
    query: parsed,
    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:



551
552
553
554
555
556
557
558
559
560
# File 'lib/docker_engine_ruby/resources/containers.rb', line 551

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

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

Unpause a container

Parameters:

Returns:

  • (nil)

See Also:



572
573
574
575
576
577
578
579
# File 'lib/docker_engine_ruby/resources/containers.rb', line 572

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:



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

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:



592
593
594
595
596
597
598
599
600
601
# File 'lib/docker_engine_ruby/resources/containers.rb', line 592

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