Start docker template via command line


Recommended Posts

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>'

Link to comment

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

  • Thanks 1
Link to comment
  • 2 years later...

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 &#xF8;, so beware. For me the docker command failed, and I could manually add that docker.

 

Best Alex

 

RunDockerTemplate.zip

Edited by Alex R. Berg
  • Thanks 1
Link to comment
  • 3 years later...

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);
?>

 

Link to comment

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?

Link to comment

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)

 

  • Thanks 2
Link to comment
  • 3 weeks later...
  • 2 months later...

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

  • Thanks 1
Link to comment
  • 1 year later...

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 by PhilBarker
wrong URL
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.