Class: DockerJail::Simple

Inherits:
Base
  • Object
show all
Defined in:
lib/docker-jail/simple.rb

Instance Attribute Summary

Attributes inherited from Base

#container, #err, #out

Instance Method Summary collapse

Methods inherited from Base

build_container, build_option, #delete, delete_all, #exit_code, #finished_at, get_all, #json, #oom_killed?, #run, #run_timeout, #started_at, #state, #timeout?

Constructor Details

#initialize(image:, cmd_list:, user: nil, workdir: nil, cpus: nil, memory_mb: nil, pids_limit: nil, binds: nil, tmpfs: nil, **other_opts) ⇒ Simple

Returns a new instance of Simple.

Parameters:

  • image (String)

    Container base image

  • cmd_list (Array<String>)

    Execute command and parameters

  • user (String) (defaults to: nil)

    (nil) Docker container’s default user is ‘root:root’.

  • cpus (String) (defaults to: nil)

    (nil)

  • memory_mb (Integer) (defaults to: nil)

    (nil) Memory limit in MB. 0 is unlimited

  • pids_limit (Integer) (defaults to: nil)

    (nil)

  • binds (Array<String>) (defaults to: nil)

    (nil) Bind mount directories

  • workdir (String) (defaults to: nil)

    (nil) The working directory.

  • tmpfs (Hash) (defaults to: nil)

    (nil) Mount empty tmpfs

  • opts (Hash)

    a customizable set of options



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/docker-jail/simple.rb', line 15

def initialize(image:, cmd_list:, user: nil, workdir: nil, cpus: nil, memory_mb: nil,
               pids_limit: nil, binds: nil, tmpfs: nil, **other_opts)
  mem_size = memory_mb&.*(1024**2)
  other_host_opts = other_opts.delete(:HostConfig)

  host_opts = {
    CpusetCpus: cpus,
    Memory: mem_size,
    MemorySwap: mem_size,
    PidsLimit: pids_limit,
    Binds: binds,
    Tmpfs: tmpfs,
  }.compact.merge(other_host_opts || {})

  opts = {
    Image: image,
    Cmd: cmd_list,
    User: user,
    WorkingDir: workdir,
    HostConfig: host_opts,
  }.compact.merge(other_opts)

  super(opts.merge(other_opts || {}))
end