title: How to execute the Entrypoint of a Docker images at each "exec" command?
body: <p>After trying to test Dockerfiles with Dockerspec, I finally had <a href="https://github.com/zuazo/dockerspec/issues/12" rel="noreferrer">an issue</a> I can't resolve properly.</p>
  
  <p>The problem is, I think, from Docker itself ; If I understand its process, <strong>an Entrypoint is only executed at run</strong>, but if the container stay started and I launch an "exec" command in, it's not re-called.</p>
  
  <p>I think it's the wanted behavior.</p>
  
  <p>But if the Entrypoint is a "<a href="https://github.com/tianon/gosu" rel="noreferrer" title="Gosu">gosu</a>" script which precede all my commands, it's a problem...</p>
  
  <hr>
  
  <p><strong>Example</strong></p>
  
  <p>"myImage" has this Entrypoint :
  <code>gosu 1000:1000 "$@"</code></p>
  
  <p>If I launch : <code>docker run -it myImage id -u</code></p>
  
  <p><em>The output is "1000".</em></p>
  
  <p>If I start a container : <code>docker run -it myImage bash</code></p>
  
  <p><em>In this container, <code>id -u</code> outputs "1000".</em></p>
  
  <p>But if I start a new command in this container, it starts a new shell, and does not execute the Entrypoint, so : <code>docker exec CONTAINER_ID id -u</code></p>
  
  <p><em>Output "0", because the new shell is started as "root".</em></p>
  
  <hr>
  
  <p>It there a way to execute each time the entrypoint ?
  Or re-use the shell open ?</p>
  
  <p>Or a better way to do that ?</p>
  
  <p>Or, maybe I haven't understand anything ? ;)</p>
  
  <p>Thanks !</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>After reading solutions proposed here, I understand that the problem is not how Docker works but how Serverspec works with ; my goal is to directly test a command as a <code>docker run</code> argument, but Serverspec start a container and test commands with <code>docker exec</code>.</p>
  
  <p>So, the best solution is to found how get the stdout of the <code>docker run</code> executed by Serverspec.</p>
  
  <p>But, in my personal use-case, the best solution is maybe to not use Gosu but --user flag :)</p>