$cpu1"; if ($cpu2) $row2[] = ""; } if ($c) echo '
'; echo ""._('CPU').":".implode($row1); if ($row2) echo "
"._('HT').":".implode($row2); } } # ██████╗ ██████╗ ██████╗ ███████╗ # ██╔════╝██╔═══██╗██╔══██╗██╔════╝ # ██║ ██║ ██║██║ ██║█████╗ # ██║ ██║ ██║██║ ██║██╔══╝ # ╚██████╗╚██████╔╝██████╔╝███████╗ # ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ########################## ## CREATE CONTAINER ## ########################## if (isset($_POST['contName'])) { $postXML = postToXML($_POST, true); $dry_run = $_POST['dryRun']=='true' ? true : false; $existing = $_POST['existingContainer'] ?? false; $create_paths = $dry_run ? false : true; // Get the command line [$cmd, $Name, $Repository] = xmlToCommand($postXML, $create_paths); readfile("$docroot/plugins/dynamix.docker.manager/log.htm"); @flush(); // Saving the generated configuration file. $userTmplDir = $dockerManPaths['templates-user']; if (!is_dir($userTmplDir)) mkdir($userTmplDir, 0777, true); if ($Name) { $filename = sprintf('%s/my-%s.xml', $userTmplDir, $Name); if (is_file($filename)) { $oldXML = simplexml_load_file($filename); if ($oldXML->Icon != $_POST['contIcon']) { if (!strpos($Repository,":")) $Repository .= ":latest"; $iconPath = $DockerTemplates->getIcon($Repository,$Name); @unlink("$docroot/$iconPath"); @unlink("{$dockerManPaths['images']}/".basename($iconPath)); } } file_put_contents($filename, $postXML); } // Run dry if ($dry_run) { echo "

XML

"; echo "
".htmlspecialchars($postXML)."
"; echo "

COMMAND:

"; echo "
".htmlspecialchars($cmd)."
"; echo "
"; echo "

"; goto END; } // Will only pull image if it's absent if (!$DockerClient->doesImageExist($Repository)) { // Pull image if (!pullImage($Name, $Repository)) { echo '

'; goto END; } } $startContainer = true; // Remove existing container if ($DockerClient->doesContainerExist($Name)) { // attempt graceful stop of container first $oldContainerInfo = $DockerClient->getContainerDetails($Name); if (!empty($oldContainerInfo) && !empty($oldContainerInfo['State']) && !empty($oldContainerInfo['State']['Running'])) { // attempt graceful stop of container first stopContainer($Name); } // force kill container if still running after 10 seconds removeContainer($Name); } // Remove old container if renamed if ($existing && $DockerClient->doesContainerExist($existing)) { // determine if the container is still running $oldContainerInfo = $DockerClient->getContainerDetails($existing); if (!empty($oldContainerInfo) && !empty($oldContainerInfo['State']) && !empty($oldContainerInfo['State']['Running'])) { // attempt graceful stop of container first stopContainer($existing); } else { // old container was stopped already, ensure newly created container doesn't start up automatically $startContainer = false; } // force kill container if still running after 10 seconds removeContainer($existing,1); // remove old template if (strtolower($filename) != strtolower("$userTmplDir/my-$existing.xml")) { @unlink("$userTmplDir/my-$existing.xml"); } } if ($startContainer) $cmd = str_replace('/docker create ', '/docker run -d ', $cmd); execCommand($cmd); echo '

'; goto END; } ########################## ## UPDATE CONTAINER ## ########################## if ($_GET['updateContainer']){ $echo = $_GET['mute'] ? false : true; if ($echo) { readfile("$docroot/plugins/dynamix.docker.manager/log.htm"); @flush(); } foreach ($_GET['ct'] as $value) { $tmpl = $DockerTemplates->getUserTemplate(urldecode($value)); if ($echo && !$tmpl) { echo ""; @flush(); continue; } $xml = file_get_contents($tmpl); [$cmd, $Name, $Repository] = xmlToCommand($tmpl); $Registry = getXmlVal($xml, "Registry"); $oldImageID = $DockerClient->getImageID($Repository); // pull image if ($echo && !pullImage($Name, $Repository)) continue; $oldContainerInfo = $DockerClient->getContainerDetails($Name); // determine if the container is still running if (!empty($oldContainerInfo) && !empty($oldContainerInfo['State']) && !empty($oldContainerInfo['State']['Running'])) { // since container was already running, put it back it to a running state after update $cmd = str_replace('/docker create ', '/docker run -d ', $cmd); // attempt graceful stop of container first stopContainer($Name, $echo); } // force kill container if still running after 10 seconds if (!$_GET['communityApplications']) removeContainer($Name, $echo); execCommand($cmd, $echo); $DockerClient->flushCaches(); $newImageID = $DockerClient->getImageID($Repository); // remove old orphan image since it's no longer used by this container if ($oldImageID && $oldImageID != $newImageID) removeImage($oldImageID, $echo); } echo '

'; goto END; } ######################### ## REMOVE TEMPLATE ## ######################### if ($_GET['rmTemplate']) { unlink($_GET['rmTemplate']); } ######################### ## LOAD TEMPLATE ## ######################### if ($_GET['xmlTemplate']) { [$xmlType, $xmlTemplate] = explode(':', urldecode($_GET['xmlTemplate'])); if (is_file($xmlTemplate)) { $xml = xmlToVar($xmlTemplate); $templateName = $xml['Name']; if ($xmlType == 'default') { if (!empty($dockercfg['DOCKER_APP_CONFIG_PATH']) && file_exists($dockercfg['DOCKER_APP_CONFIG_PATH'])) { // override /config foreach ($xml['Config'] as &$arrConfig) { if ($arrConfig['Type'] == 'Path' && strtolower($arrConfig['Target']) == '/config') { $arrConfig['Default'] = $arrConfig['Value'] = realpath($dockercfg['DOCKER_APP_CONFIG_PATH']).'/'.$xml['Name']; if (empty($arrConfig['Display']) || preg_match("/^Host Path\s\d/", $arrConfig['Name'])) { $arrConfig['Display'] = 'advanced-hide'; } if (empty($arrConfig['Name']) || preg_match("/^Host Path\s\d/", $arrConfig['Name'])) { $arrConfig['Name'] = 'AppData Config Path'; } } } } if (!empty($dockercfg['DOCKER_APP_UNRAID_PATH']) && file_exists($dockercfg['DOCKER_APP_UNRAID_PATH'])) { // override /unraid $boolFound = false; foreach ($xml['Config'] as &$arrConfig) { if ($arrConfig['Type'] == 'Path' && strtolower($arrConfig['Target']) == '/unraid') { $arrConfig['Default'] = $arrConfig['Value'] = realpath($dockercfg['DOCKER_APP_UNRAID_PATH']); $arrConfig['Display'] = 'hidden'; $arrConfig['Name'] = 'Unraid Share Path'; $boolFound = true; } } if (!$boolFound) { $xml['Config'][] = [ 'Name' => 'Unraid Share Path', 'Target' => '/unraid', 'Default' => realpath($dockercfg['DOCKER_APP_UNRAID_PATH']), 'Value' => realpath($dockercfg['DOCKER_APP_UNRAID_PATH']), 'Mode' => 'rw', 'Description' => '', 'Type' => 'Path', 'Display' => 'hidden', 'Required' => 'false', 'Mask' => 'false' ]; } } } $xml['Description'] = str_replace(['[', ']'], ['<', '>'], $xml['Overview']); echo ""; } } echo ""; $authoringMode = $dockercfg['DOCKER_AUTHORING_MODE'] == "yes" ? true : false; $authoring = $authoringMode ? 'advanced' : 'noshow'; $disableEdit = $authoringMode ? 'false' : 'true'; $showAdditionalInfo = ''; $bgcolor = strstr('white,azure',$display['theme']) ? '#f2f2f2' : '#1c1c1c'; ?> "> "> "> ">
doesContainerExist($templateName)):?>
_(Template)_: : :help1 > Templates are a quicker way to setting up Docker Containers on your Unraid server. There are two types of templates: > > **Default templates**
> When valid repositories are added to your Docker Repositories page, they will appear in a section on this drop down for you to choose (master categorized by author, then by application template). > After selecting a default template, the page will populate with new information about the application in the Description field, and will typically provide instructions for how to setup the container. > Select a default template when it is the first time you are configuring this application. > > **User-defined templates**
> Once you've added an application to your system through a Default template, > the settings you specified are saved to your USB flash device to make it easy to rebuild your applications in the event an upgrade were to fail or if another issue occurred. > To rebuild, simply select the previously loaded application from the User-defined list and all the settings for the container will appear populated from your previous setup. > Clicking create will redownload the necessary files for the application and should restore you to a working state. > To delete a User-defined template, select it from the list above and click the red X to the right of it. :end
_(Name)_: : :help2 > Give the container a name or leave it as default. :end
_(Overview)_: :
_(Overview)_: : :help3 > A description for the application container. Supports basic HTML mark-up. :end
_(Repository)_: : :help4 > The repository for the application on the Docker Registry. Format of authorname/appname. > Optionally you can add a : after appname and request a specific version for the container image. :end
_(Categories)_: : _(Support Thread)_: : :help5 > Link to a support thread on Lime-Technology's forum. :end _(Project Page)_: : :help6 > Link to the project page (eg: www.plex.tv) :end _(Donation Text)_: : :help7 > Text to appear on Donation Links Within The Apps Tab :end _(Donation Link)_: : :help8 > Link to the donation page. If using donation's, both the image and link must be set :end
_(Docker Hub URL)_: : :help9 > The path to the container's repository location on the Docker Hub. :end
_(Template URL)_: : :help10 > This URL is used to keep the template updated. :end
_(Icon URL)_: : :help11 > Link to the icon image for your application (only displayed on dashboard if Show Dashboard apps under Display Settings is set to Icons). :end _(WebUI)_: : :help12 > When you click on an application icon from the Docker Containers page, the WebUI option will link to the path in this field. > Use [IP] to identify the IP of your host and [PORT:####] replacing the #'s for your port. :end _(Extra Parameters)_: : :help13 > If you wish to append additional commands to your Docker container at run-time, you can specify them here.
> For all possible Docker run-time commands, see here: https://docs.docker.com/reference/run/ :end _(Post Arguments)_: : :help14 > If you wish to append additional arguments AFTER the container definition, you can specify them here. > The content of this field is container specific. :end _(CPU Pinning)_: : :help15 > 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) :end
_(Network Type)_: :
_(Fixed IP address)_ (_(optional)_): : :help16 > If the Bridge type is selected, the application’s network access will be restricted to only communicating on the ports specified in the port mappings section. > If the Host type is selected, the application will be given access to communicate using any port on the host that isn’t already mapped to another in-use application/service. > Generally speaking, it is recommended to leave this setting to its default value as specified per application template. > > IMPORTANT NOTE: If adjusting port mappings, do not modify the settings for the Container port as only the Host port can be adjusted. :end
_(Console shell command)_: : _(Privileged)_: : :help17 > For containers that require the use of host-device access directly or need full exposure to host capabilities, this option will need to be selected. > For more information, see this link: https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities :end
  : _(Show more settings)_ ...   : _(Show docker allocations)_ ...   : _(Add another Path, Port, Variable, Label or Device)_   :