title: Docker Go template extract image shortname
body: <p>I'm looking to understand how to extract values using pattern matching, or string splitting techniques etc in the golang template. As an example, I can retrieve the following value from docker inspect:</p>
  <pre><code>$ docker inspect --format '{{ .Config.Image }}' hello_world-0f87ch
  registry.example.com/hello_world:0.1.0
  </code></pre>
  <p>But what I need is to apply some pattern match to extract the image shortname without the tag like so:</p>
  <pre><code>$ docker inspect --format '{{ &lt;some templating logic&gt; }}' hello_world-0f87ch
  hello_world
  </code></pre>
  <p>This is an example to highlight, the real case scenario sets the template format in a config file so will not have access to bash at runtime (so I can't simply pipe the result etc).</p>
  <p>I'm new to the templating language so can someone please help with the simple check (between <code>/</code> and <code>:</code>) ?</p>
  <h1>SOLVED</h1>
  <p>Managed it with thanks to invad0r's answer. Extending what he wrote I ended up with:</p>
  <pre><code>'{{$v1 := split .Config.Image &quot;:&quot;}}{{ $v2 := join $v1 &quot;/&quot; }}{{$v3 := split $v2 &quot;/&quot;}}{{$shortName := index $v3 1}}{{$shortName}}'
  </code></pre>