Skip to content

Commit

Permalink
Support setting shared memory size.
Browse files Browse the repository at this point in the history
This change enables setting the shared memory size of a container,
as one would with `docker run --shm-size ...`.

This functionality was added in Docker 1.10.0 - this would break older
Dockers. I do not know what level of compatibility this project
attempts to maintain with Docker itself.

Signed-off-by: Don Luchini <[email protected]>
  • Loading branch information
don-code committed Feb 3, 2019
1 parent 7fc06fc commit e1fe994
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ Most `docker_container` properties are the `snake_case` version of the `CamelCas
- `running_wait_time` - Amount of seconds `docker_container` wait to determine if a process is running.
- `runtime` - Runtime to use when running container. Defaults to `runc`.
- `security_opt` - A list of string values to customize labels for MLS systems, such as SELinux.
- `shm_size` - The size of `/dev/shm`. The format is `<number><unit>`, where number must be greater than 0. Unit is optional and can be b (bytes), k (kilobytes), m(megabytes), or g (gigabytes). The default is `64m`.
- `signal` - The signal to send when using the `:kill` action. Defaults to `SIGTERM`.
- `sysctls` - A hash of sysctls to set on the container. Defaults to `{}`.
- `tty` - Boolean value to allocate a pseudo-TTY. Defaults to `false`.
Expand Down
2 changes: 2 additions & 0 deletions libraries/docker_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class DockerContainer < DockerBase
property :runtime, String, default: 'runc'
property :ro_rootfs, [TrueClass, FalseClass], default: false
property :security_opt, [String, Array], coerce: proc { |v| v.nil? ? nil : Array(v) }
property :shm_size, [String, Integer], default: '64m', coerce: proc { |v| coerce_to_bytes(v) }
property :signal, String, default: 'SIGTERM'
property :stdin_once, [TrueClass, FalseClass], default: false, desired_state: false
property :sysctls, Hash, default: {}
Expand Down Expand Up @@ -538,6 +539,7 @@ def load_container_labels
'ReadonlyRootfs' => new_resource.ro_rootfs,
'Runtime' => new_resource.runtime,
'SecurityOpt' => new_resource.security_opt,
'ShmSize' => new_resource.shm_size,
'Sysctls' => new_resource.sysctls,
'Ulimits' => ulimits_to_hash,
'UsernsMode' => new_resource.userns_mode,
Expand Down
1 change: 1 addition & 0 deletions test/cookbooks/docker_test/recipes/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@
memory_swap '5M'
memory_swappiness 50
memory_reservation '5m'
shm_size '32m'
action :run
end

Expand Down

0 comments on commit e1fe994

Please sign in to comment.