|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="chrome=1"> |
| 6 | + <title>Docker Exec</title> |
| 7 | + |
| 8 | + <link rel="stylesheet" href="stylesheets/styles.css"> |
| 9 | + <link rel="stylesheet" href="stylesheets/pygment_trac.css"> |
| 10 | + <script src="javascripts/scale.fix.js"></script> |
| 11 | + <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> |
| 12 | + |
| 13 | + <!--[if lt IE 9]> |
| 14 | + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 15 | + <![endif]--> |
| 16 | + </head> |
| 17 | + <body> |
| 18 | + <div class="wrapper"> |
| 19 | + <header> |
| 20 | + <h1>Docker Exec</h1> |
| 21 | + <p>Execute code in many languages with Docker!</p> |
| 22 | + <p class="view"><a href="https://github.com/docker-exec/dexec">View the Project on GitHub</a></p> |
| 23 | + <ul> |
| 24 | + <li class="single"><a href="https://github.com/docker-exec/dexec">View On <strong>GitHub</strong></a></li> |
| 25 | + </ul> |
| 26 | + </header> |
| 27 | + <section> |
| 28 | + <h3> |
| 29 | +<a id="what" class="anchor" href="#what" aria-hidden="true"><span class="octicon octicon-link"></span></a>What?</h3> |
| 30 | + |
| 31 | +<p>Docker Exec is a collection of Docker images capable of executing code in many different programming languages without requiring a single compiler or script interpreter on your machine.</p> |
| 32 | + |
| 33 | +<p>The <code>dexec</code> command line interface provides a simple front end, picking the appropriate Docker image based on the source extension.</p> |
| 34 | + |
| 35 | +<p><strong>See the <a href="https://github.com/docker-exec/dexec/blob/master/README.md#installation">dexec installation guide</a> to get started</strong></p> |
| 36 | + |
| 37 | +<p><img src="https://docker-exec.github.io/images/dexec-short.gif" alt="dexec demo animation"></p> |
| 38 | + |
| 39 | +<p>Let's take a closer look at one of the examples, <a href="https://github.com/docker-exec/cpp/blob/v1.0.0/test/helloworld.cpp">helloworld.cpp</a>:</p> |
| 40 | + |
| 41 | +<div class="highlight highlight-c++"><pre>#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds"><</span>iostream<span class="pl-pds">></span></span> |
| 42 | +<span class="pl-k">int</span> <span class="pl-en">main</span>() { |
| 43 | + std::cout << <span class="pl-s"><span class="pl-pds">"</span>Hello, World!<span class="pl-pds">"</span></span> << std::endl; |
| 44 | + <span class="pl-k">return</span> <span class="pl-c1">0</span>; |
| 45 | +}</pre></div> |
| 46 | + |
| 47 | +<p>executing it is simple:</p> |
| 48 | + |
| 49 | +<pre><code>$ dexec foo.cpp |
| 50 | + |
| 51 | +Hello, World! |
| 52 | +</code></pre> |
| 53 | + |
| 54 | +<p>Docker Exec also supports passing arguments to the executing program, passing arguments to the compiler, mounting extra files and directories in the executing container as well as the ability to make source files executable as scripts using a shebang.</p> |
| 55 | + |
| 56 | +<h3> |
| 57 | +<a id="why" class="anchor" href="#why" aria-hidden="true"><span class="octicon octicon-link"></span></a>Why?</h3> |
| 58 | + |
| 59 | +<p>Docker Exec allows you to run code in a compiled language just as easily as you can for interpreted languages. This is useful for speeding up your ability to try things out in compiled languages.</p> |
| 60 | + |
| 61 | +<p>The <a href="https://github.com/docker-exec/dexec/blob/master/README.md#reference">uniform interface</a> used to execute source for all of the different languages means that calls to <code>dexec</code> can be shelled out from other programs who need to execute arbitrary source, for example automated answer checkers for code tests in pre-interview situations or for university exercises.</p> |
| 62 | + |
| 63 | +<p>Another benefit is that the only dependency on your machine becomes Docker instead of lots of different compilers and interpreters. Docker is a powerful tool and a lot is said about its potential for running web services and databases. However, it's also great for single program execution too and this is an example of how tools can be usefully virtualised just as well as web services.</p> |
| 64 | + |
| 65 | +<p>Further to this, the virtualisation of the compilation and execution acts as a sandbox in the event you're not entirely sure how safe a piece of code is to run.</p> |
| 66 | + |
| 67 | +<h3> |
| 68 | +<a id="how" class="anchor" href="#how" aria-hidden="true"><span class="octicon octicon-link"></span></a>How?</h3> |
| 69 | + |
| 70 | +<p>A Docker image exists for each target language, with an associated automated build job on Docker Hub. The image contains the compiler, runtime or interpreter for that language and a <a href="https://github.com/docker-exec/image-common">bash script</a> that does any of the following depending on the language:</p> |
| 71 | + |
| 72 | +<ul> |
| 73 | +<li>Compile the code and run the compiled executable.</li> |
| 74 | +<li>Compile the code and use a runtime to execute the compiled bytecode.</li> |
| 75 | +<li>Pass the code to a script interpreter.</li> |
| 76 | +</ul> |
| 77 | + |
| 78 | +<p>The <code>dexec</code> utility wraps the following command:</p> |
| 79 | + |
| 80 | +<div class="highlight highlight-sh"><pre>$ docker run -t --rm \ |
| 81 | + -v <span class="pl-s"><span class="pl-pds">$(</span><span class="pl-c1">pwd</span> -P<span class="pl-pds">)</span></span>/foo.cpp:/tmp/dexec/build/foo.cpp \ |
| 82 | + dexec/cpp foo.cpp</pre></div> |
| 83 | + |
| 84 | +<p>Arguments can be passed to the executing code using:</p> |
| 85 | + |
| 86 | +<pre><code>-a bar |
| 87 | +--arg bar |
| 88 | +--arg=bar |
| 89 | +</code></pre> |
| 90 | + |
| 91 | +<p>Arguments can be passed to the compiler (if the language has one) using:</p> |
| 92 | + |
| 93 | +<pre><code>-b foo |
| 94 | +--build-arg foo |
| 95 | +--build-arg=foo |
| 96 | +</code></pre> |
| 97 | + |
| 98 | +<p>Extra file and folders can be mounted in the container with <code>dexec</code> using:</p> |
| 99 | + |
| 100 | +<pre><code>-i foo.hpp |
| 101 | +--include foo.hpp |
| 102 | +--include=foo.hpp |
| 103 | +</code></pre> |
| 104 | + |
| 105 | +<p>Prefixing a source file with a shebang that invokes dexec will make it executable:</p> |
| 106 | + |
| 107 | +<pre><code>#!/usr/bin/env dexec |
| 108 | +</code></pre> |
| 109 | + |
| 110 | +<h3> |
| 111 | +<a id="where" class="anchor" href="#where" aria-hidden="true"><span class="octicon octicon-link"></span></a>Where?</h3> |
| 112 | + |
| 113 | +<ul> |
| 114 | +<li><a href="https://github.com/docker-exec/dexec">dexec on GitHub</a></li> |
| 115 | +<li><a href="https://bintray.com/dexec/release/dexec/view">dexec on Bintray</a></li> |
| 116 | +<li><a href="https://github.com/docker-exec">Docker Exec GitHub Repositories</a></li> |
| 117 | +<li><a href="https://hub.docker.com/repos/dexec/">Docker Exec Images on Docker Hub</a></li> |
| 118 | +</ul> |
| 119 | + |
| 120 | +<h3> |
| 121 | +<a id="which" class="anchor" href="#which" aria-hidden="true"><span class="octicon octicon-link"></span></a>Which?</h3> |
| 122 | + |
| 123 | +<p>The following languages are available:</p> |
| 124 | + |
| 125 | +<ul> |
| 126 | +<li><a href="https://github.com/docker-exec/bash">Bash</a></li> |
| 127 | +<li><a href="https://github.com/docker-exec/c">C</a></li> |
| 128 | +<li><a href="https://github.com/docker-exec/clojure">Clojure</a></li> |
| 129 | +<li><a href="https://github.com/docker-exec/coffee">CoffeeScript</a></li> |
| 130 | +<li><a href="https://github.com/docker-exec/cpp">C++</a></li> |
| 131 | +<li><a href="https://github.com/docker-exec/csharp">C#</a></li> |
| 132 | +<li><a href="https://github.com/docker-exec/d">D</a></li> |
| 133 | +<li><a href="https://github.com/docker-exec/erlang">Erlang</a></li> |
| 134 | +<li><a href="https://github.com/docker-exec/fsharp">F#</a></li> |
| 135 | +<li><a href="https://github.com/docker-exec/go">Go</a></li> |
| 136 | +<li><a href="https://github.com/docker-exec/groovy">Groovy</a></li> |
| 137 | +<li><a href="https://github.com/docker-exec/haskell">Haskell</a></li> |
| 138 | +<li><a href="https://github.com/docker-exec/java">Java</a></li> |
| 139 | +<li><a href="https://github.com/docker-exec/lisp">Lisp</a></li> |
| 140 | +<li><a href="https://github.com/docker-exec/node">Node JS</a></li> |
| 141 | +<li><a href="https://github.com/docker-exec/objc">Objective C</a></li> |
| 142 | +<li><a href="https://github.com/docker-exec/ocaml">OCaml</a></li> |
| 143 | +<li><a href="https://github.com/docker-exec/perl">Perl</a></li> |
| 144 | +<li><a href="https://github.com/docker-exec/php">PHP</a></li> |
| 145 | +<li><a href="https://github.com/docker-exec/python">Python</a></li> |
| 146 | +<li><a href="https://github.com/docker-exec/racket">Racket</a></li> |
| 147 | +<li><a href="https://github.com/docker-exec/ruby">Ruby</a></li> |
| 148 | +<li><a href="https://github.com/docker-exec/rust">Rust</a></li> |
| 149 | +<li><a href="https://github.com/docker-exec/scala">Scala</a></li> |
| 150 | +</ul> |
| 151 | + |
| 152 | +<h3> |
| 153 | +<a id="who" class="anchor" href="#who" aria-hidden="true"><span class="octicon octicon-link"></span></a>Who?</h3> |
| 154 | + |
| 155 | +<p>I'm Andy Stanton (<a href="https://github.com/andystanton">@andystanton</a>).</p> |
| 156 | + |
| 157 | +<h3> |
| 158 | +<a id="help" class="anchor" href="#help" aria-hidden="true"><span class="octicon octicon-link"></span></a>Help!</h3> |
| 159 | + |
| 160 | +<p>Documentation can be found and issues raised in each image's repository.</p> |
| 161 | + </section> |
| 162 | + </div> |
| 163 | + <footer> |
| 164 | + <p>Hosted on GitHub Pages — Theme by <a href="https://github.com/orderedlist">orderedlist</a></p> |
| 165 | + </footer> |
| 166 | + <!--[if !IE]><script>fixScale(document);</script><![endif]--> |
| 167 | + <script type="text/javascript"> |
| 168 | + var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 169 | + document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| 170 | + </script> |
| 171 | + <script type="text/javascript"> |
| 172 | + try { |
| 173 | + var pageTracker = _gat._getTracker("UA-48544248-4"); |
| 174 | + pageTracker._trackPageview(); |
| 175 | + } catch(err) {} |
| 176 | + </script> |
| 177 | + |
| 178 | + </body> |
| 179 | +</html> |
0 commit comments