title: Parsing Docker image tag into component parts
body: <p>A canonical Docker image tag is in the form:</p>
  
  <pre><code>[[registry-address]:port/]name:tag
  </code></pre>
  
  <p>The address and port can be omitted, in which case Docker goes to the default registry which is the Docker Hub. For example the following are all valid:</p>
  
  <pre><code>ubuntu:latest
  nixos/nix:1.10
  localhost:5000/myfirstimage:latest
  localhost:5000/nixos/nix:latest
  </code></pre>
  
  <p>I need some code that will parse this string reliably into its component parts. However it seems impossible to do this unambiguously because the "name" component can contain a slash. For example the following tag is ambiguous:</p>
  
  <pre><code>localhost/myfirstimage:latest
  </code></pre>
  
  <p>This could be an image with name <code>localhost/myfirstimage</code> on the Docker Hub, or it could be an image with the name <code>myfirstimage</code> on the registry running at address <code>localhost</code>.</p>
  
  <p>Does anybody know how Docker itself parses such input?</p>