title: Dynamically get docker image id from its name
body: <p>I need to dynamically delete all docker images in a server, except for the postgres image and container.</p>
  
  <p>Now I need a dynamic way to get the id of that docker image so i will know to avoid it, using:</p>
  
  <pre><code>docker rmi $(docker images -q | grep -v $&lt;id_of_postgres_container&gt;)
  </code></pre>
  
  <p>For the container part, i managed to find this:</p>
  
  <pre><code>docker ps -aqf "name=postgres"
  </code></pre>
  
  <p>which returns only the id of the postgres container. Is there any way to do the same with images without getting too deep into bash scripting? </p>
  
  <p>or any better suggestions?</p>