title: determine OS distribution of a docker image
body: <p>I need to determine the OS distribution name for any docker image. I can tag <strong>ubuntu:latest</strong> as <strong>image1:latest</strong>, but I should be able to get the distribution information of image1:latest when it is launched.</p>
  
  <p>For achieving this, I used the below mentioned command to determine the OS version:</p>
  
  <pre><code>$ docker tag ubuntu image1
  $
  $ docker run -it image1 /bin/sh -c "echo import platform &gt; test.py; echo print\(platform.dist\(\)\) &gt;&gt; test.py; python3 test.py"
  ('Ubuntu', '14.04', 'trusty')
  $
  </code></pre>
  
  <p>However, this has a dependency on whether the image has <strong>python2</strong> or <strong>python3</strong> in it. It fails for ubuntu:12.04 and I need to use python2 there.</p>
  
  <pre><code>$ docker run -it ubuntu /bin/sh -c "echo import platform &gt; test.py; echo print\(platform.dist\(\)\) &gt;&gt; test.py; python3 test.py"
  ('Ubuntu', '14.04', 'trusty')
  $
  $ docker run -it ubuntu:12.04 /bin/sh -c "echo import platform &gt; test.py; echo print\(platform.dist\(\)\) &gt;&gt; test.py; python3 test.py"
  /bin/sh: 1: python3: not found
  $
  $ docker run -it ubuntu:12.04 /bin/sh -c "echo import platform &gt; test.py; echo print\(platform.dist\(\)\) &gt;&gt; test.py; python2 test.py"
  ('Ubuntu', '12.04', 'precise')
  $ 
  </code></pre>
  
  <p>Q1. Is there a way I can achieve the same without knowing which version of python is there in a particular image?</p>
  
  <p>NOTE: The goal is to determine which was the base image used to build this image. I don't have access to the Dockerfile used to build this image.</p>
  
  <p>Q2. There is another approach of using entrypoint. I can build a separate image from the current image using Dockerfile. Or, I can specify entrypoint in cmdline when creating container but I need the script to be accessible within the container. I am guessing that I might need shared storage when using cmdline, is there a better way to achieve this? Any pointers would be really helpful.</p>
  
  <p>Thanks.</p>