title: How to use the (short) git commit hash to tag image versions in Docker Compose file
body: <p>From the <a href="https://docs.docker.com/compose/compose-file/#build" rel="noreferrer">official Docker Compose build doc</a>:</p>
  
  <blockquote>
    <p>If you specify image as well as build, then Compose names the built image with the webapp and optional tag specified in image:</p>
  </blockquote>
  
  <p>Example:</p>
  
  <pre><code>build: 
     ...
  image: myapp:tag
  </code></pre>
  
  <p>but I would like to replace <code>tag</code> with the output of <code>git rev-parse --short HEAD</code>.</p>
  
  <p>Ideally I need something like:</p>
  
  <pre><code>image: myapp:$(git rev-parse --short HEAD)
  </code></pre>