Sunday, March 19, 2017

Command-line Docker tip

If you're developing/running command line tools in Docker containers, you'll probably want the tool to know from what folder you're running the tool. To do this, you'll want to pass the "-v `pwd`:/source" option, where:
  • "pwd" (surrounded by backticks) is aliased to the working directory within the container
  • "/source" is the internal working directory within the container

For this (above and below) example, I'm using the Pandoc container, developed by jagregory. If I save the script (below) as "md2pdf", the syntax to run it would be something like:

  md2pdf result.pdf

My Script:



# following must be "beamer" or "latex"
# note: use beamer when producing PDF slides 
#       and latex when producing papers

#$format = "beamer";
$format = "latex";

if($format eq "latex") {
 $margin="-V geometry:margin=1in";
 $toc = "--toc";
 $highlight = "--listings --highlight-style=tango";

system("sudo docker run --rm -v `pwd`:/source pg/pandoc $toc $margin \
  $highlight -f markdown -t $format $src -o $tgt");

No comments:

Post a Comment