Skip to content

Commit 4d18192

Browse files
elibosleyclaude
andcommitted
feat(docker): expose memory (RAM) limit as an Advanced View field
Add a "Memory limit" field to the Docker Add/Edit form (Advanced View) that maps to docker --memory, instead of requiring users to hand-write it in Extra Parameters. Empty leaves the container unlimited (unchanged default). The value round-trips through the container XML template (<Memory>) and is emitted as --memory=<value> in the docker create command. Closes OS-467 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 644ab82 commit 4d18192

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

emhttp/languages/en_US/helptext.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,12 @@ If you wish to append additional arguments AFTER the container definition, you c
23672367
The content of this field is container specific.
23682368
:end
23692369

2370+
:docker_memory_limit_help:
2371+
The maximum amount of memory the container is allowed to use (Docker <code>--memory</code>).<br>
2372+
Use a plain number for bytes, or a suffix: <b>b</b>, <b>k</b>, <b>m</b>, <b>g</b> (for example <b>512m</b> or <b>2g</b>). The minimum allowed value is 6m.<br>
2373+
Leave empty for no limit (default). If you also set <code>--memory</code> in Extra Parameters, that value takes precedence.
2374+
:end
2375+
23702376
:docker_cpu_pinning_help:
23712377
Checking a CPU core(s) will limit the container to run on the selected cores only. Selecting no cores lets the container run on all available cores (default)
23722378
:end

emhttp/plugins/dynamix.docker.manager/include/CreateDocker.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,11 @@ function prepareCategory() {
11481148

11491149
:docker_extra_parameters_help:
11501150

1151+
_(Memory limit)_:
1152+
: <input type="text" name="contMemory" placeholder="_(unlimited)_" pattern="[0-9]+[bkmgBKMG]?" title="_(Number of bytes, or a number followed by b, k, m or g (e.g. 512m, 2g))_">
1153+
1154+
:docker_memory_limit_help:
1155+
11511156
_(Post Arguments)_:
11521157
: <input type="text" name="contPostArgs">
11531158

emhttp/plugins/dynamix.docker.manager/include/Helpers.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function postToXML($post, $setOwnership=false) {
151151
$xml->ExtraParams = xml_encode($myMAC && !$extraNetwork ? removeMacAddressParam($post['contExtraParams']) : $post['contExtraParams']);
152152
$xml->PostArgs = xml_encode($post['contPostArgs']);
153153
$xml->CPUset = xml_encode($post['contCPUset']);
154+
$xml->Memory = xml_encode(trim($post['contMemory']??''));
154155
$xml->DateInstalled = xml_encode(time());
155156
$xml->DonateText = xml_encode($post['contDonateText']);
156157
$xml->DonateLink = xml_encode($post['contDonateLink']);
@@ -415,6 +416,7 @@ function xmlToCommand($xml, $create_paths=false) {
415416
foreach (explode(' ',str_replace(',',' ',$xml['MyIP'])) as $myIP) if ($myIP) $cmdMyIP .= (strpos($myIP,':') !== false ? '--ip6=' : '--ip=').escapeshellarg($myIP).' ';
416417
}
417418
$cmdCPUset = strlen($xml['CPUset']) ? '--cpuset-cpus='.escapeshellarg($xml['CPUset']) : '';
419+
$cmdMemory = strlen($xml['Memory']??'') ? '--memory='.escapeshellarg($xml['Memory']) : '';
418420
$Volumes = [''];
419421
$Ports = [''];
420422
$Variables = [''];
@@ -562,8 +564,8 @@ function xmlToCommand($xml, $create_paths=false) {
562564
$pid_limit = "";
563565
}
564566

565-
$cmd = sprintf($docroot.'/plugins/dynamix.docker.manager/scripts/docker create %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s',
566-
$cmdName, $TS_entrypoint, $cmdNetwork, $cmdMyIP, $cmdCPUset, $pid_limit, $cmdPrivileged, implode(' -e ', $Variables), $TS_hostname, $TS_exitnode, $TS_exitnode_ip, $TS_lan_access, $TS_routes, $TS_accept_routes, $TS_ssh, $TS_userspace_networking, $TS_serve_funnel, $TS_serve_port, $TS_serve_target, $TS_serve_local_path, $TS_serve_protocol, $TS_serve_protocol_port, $TS_serve_path, $TS_daemon_params, $TS_extra_params, $TS_state_dir, $TS_troubleshooting, $TS_postargs, implode(' -l ', $Labels), $TS_web_ui, $TS_hostname_label, implode(' -p ', $Ports), implode(' -v ', $Volumes), $TS_hook, $TS_cap, $TS_tundev, implode(' --device=', $Devices), $xml['ExtraParams'], escapeshellarg($xml['Repository']), $xml['PostArgs']);
567+
$cmd = sprintf($docroot.'/plugins/dynamix.docker.manager/scripts/docker create %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s',
568+
$cmdName, $TS_entrypoint, $cmdNetwork, $cmdMyIP, $cmdCPUset, $cmdMemory, $pid_limit, $cmdPrivileged, implode(' -e ', $Variables), $TS_hostname, $TS_exitnode, $TS_exitnode_ip, $TS_lan_access, $TS_routes, $TS_accept_routes, $TS_ssh, $TS_userspace_networking, $TS_serve_funnel, $TS_serve_port, $TS_serve_target, $TS_serve_local_path, $TS_serve_protocol, $TS_serve_protocol_port, $TS_serve_path, $TS_daemon_params, $TS_extra_params, $TS_state_dir, $TS_troubleshooting, $TS_postargs, implode(' -l ', $Labels), $TS_web_ui, $TS_hostname_label, implode(' -p ', $Ports), implode(' -v ', $Volumes), $TS_hook, $TS_cap, $TS_tundev, implode(' --device=', $Devices), $xml['ExtraParams'], escapeshellarg($xml['Repository']), $xml['PostArgs']);
567569
return [preg_replace('/\s\s+/', ' ', $cmd), $xml['Name'], $xml['Repository']];
568570
}
569571
function stopContainer($name, $t=false, $echo=true) {

0 commit comments

Comments
 (0)