skidelo Posted July 22, 2015 Share Posted July 22, 2015 Is it possible to start a docker container based on an .xml template via the command line? I'm aware of 'docker run <docker image> -v <volumes> etc...' However, all of the these run arguments are stored in xml files in /boot/config/plugins/dockerMan/templates-user I know the docker plugin uses these, but I only have ssh access when I'm away from my local network, so I have no GUI access to start them. So basically i'm looking for something along the lines of: 'docker_plugin run <my-container-template.xml>' Quote Link to comment
smdion Posted July 22, 2015 Share Posted July 22, 2015 Someone can correct me if I'm wrong. But the Community Apps/DockerMan pages scrape the XML for the needed info to get the same "docker run" command. I keep a Simplenote sheet with all my run commands. Quote Link to comment
Squid Posted July 22, 2015 Share Posted July 22, 2015 Community Apps/DockerMan pages scrape the XML for the needed info to get the same "docker run" command. Correct. Shouldn't actually be that big a job to come up with script to do the same thing Quote Link to comment
trurl Posted July 22, 2015 Share Posted July 22, 2015 You could probably come up with some XSL and plug it in here. Quote Link to comment
skidelo Posted July 22, 2015 Author Share Posted July 22, 2015 Cool. I'll look into it and post back. Just didn't want to re-invent the wheel if it was already done. Quote Link to comment
skidelo Posted July 26, 2015 Author Share Posted July 26, 2015 Well, I made a bash script that parses xml template files and executes 'docker run -d' with the appropriate arguments populated from the template file. The script takes one argument: The path to the .xml template file. ./RunDockerTemplate.sh <path_to_xml_template_file> I've been running into problems with volume mappings that have spaces in their path (ie. /mnt/user/my media). This is a known bug. If any of you guys are bash scripting gurus, please feel free to fix my script! Anyway - the point of this was to be able to edit docker containers without having to login to the GUI. This is useful for me if I am away from my home network and only have SSH access. Unzip the script by executing: unzip RunDockerTemplate.zip Hope it helps someone out! RunDockerTemplate.zip 1 Quote Link to comment
Alex R. Berg Posted January 11, 2018 Share Posted January 11, 2018 (edited) Awesome script Skidelo, I've been looking for something like that. I've updated the script. I found some problems, and have fixet some of them. Maybe the xml format or parse has changed. Changes: Fixed parsing of muliple volumes and ports (didn't Added quotes around volumes Parse multiple files like with *.xml Added dryrun and verbose flags Current Problem: The xmlint xml-decoder does not parse xml-encoded strings like ø, so beware. For me the docker command failed, and I could manually add that docker. Best Alex RunDockerTemplate.zip Edited January 11, 2018 by Alex R. Berg 1 Quote Link to comment
Squid Posted August 7, 2021 Share Posted August 7, 2021 Ran across this thread. My solution: pass the path to the xml as the argument to the script. Should work with absolutely any xml #!/usr/bin/php <? $docroot = "/usr/local/emhttp"; require_once "$docroot/plugins/dynamix.docker.manager/include/DockerClient.php"; $var = parse_ini_file('/var/local/emhttp/var.ini'); $cfg = parse_ini_file('/boot/config/docker.cfg'); $driver = DockerUtil::driver(); $custom = DockerUtil::custom(); $subnet = DockerUtil::network($custom); $opts = xmlToCommand($argv[1]); $cmd = str_replace("create ","run -d ",$opts[0]); passthru($cmd); ?> Quote Link to comment
DeathStar Darth Posted August 7, 2021 Share Posted August 7, 2021 I was reading this old article when you replied to it @Squid! I tried your above script with both the script and my xml in /tmp, but got an error root@TheDeathStar:/tmp# ./runxml.sh my-gluetun.xml Warning: parse_ini_file($docroot/state/var.ini): failed to open stream: No such file or directory in /tmp/runxml.sh on line 7 docker: invalid reference format. See 'docker run --help'. The path/file set in $var exists. root@TheDeathStar:/tmp# ls -lartih /usr/local/emhttp/state/var.ini 3243287 -rw-rw-rw- 1 root root 3.3K Aug 7 03:21 /usr/local/emhttp/state/var.ini as does that for $cfg root@TheDeathStar:/tmp# ls -lartih /boot/config/docker.cfg 11063 -rw------- 1 root root 350 Jul 30 16:14 /boot/config/docker.cfg Can you offer any pointers as to what I should follow up on to resolve? Quote Link to comment
Squid Posted August 7, 2021 Share Posted August 7, 2021 Adjusted the path on my post. It was a result of my dev environment Also, the path you're passing thru to the command should be /boot/config/plugins/dockerMan/templates-user/my-gluetun.xml (which is presumably where its located and not in the current directory (/tmp) 2 Quote Link to comment
DeathStar Darth Posted August 26, 2021 Share Posted August 26, 2021 Thanks @Squid that works perfectly now, and much appreciated. Quote Link to comment
mDrewitt Posted October 26, 2021 Share Posted October 26, 2021 After finding this thread (Thanks everyone!) I ended up having to make some modifications to run it on my server running the latest Unraid (6.9.2) I updated all the xpath to be more modern/proper (eg. //Name -> /descendant::Name etc) as it was not working correctly with env vars anymore. I also changed a couple things I noticed were different like it always binding the TZ, adding HOST_OS and quoting using single not double quotes among a couple other things. I thought I might as well share my work incase someone is looking for this kinda thing and doesn't have the know-how to update this script. Also, a tip of how I managed this script, I used the user scripts plugin to put the script in for easy management, and then just run it from there (dry-run and verbose in this case): sh /boot/config/plugins/user.scripts/scripts/runDockerTemplate/script -yv /boot/config/plugins/dockerMan/templates-user/my-xml-file.xml RunDockerTemplate.zip 1 Quote Link to comment
PhilBarker Posted November 24, 2022 Share Posted November 24, 2022 (edited) I found this thread through a link in the Rebuild-DNDC package It was using this script to convert the XML into a docker command to restart child containers linked to a parent container network. It stopped working at some point, wasn't finding volumes etc... I believe the XML format must have changed in the last year I've written a quick and dirty update to it which I thought I'd link here just in case anyone is still looking for this functionality https://github.com/Phil-Barker/rebuild-dndc/blob/master/Rebuild-DNDC/ParseDockerTemplate.sh Edited November 24, 2022 by PhilBarker wrong URL Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.