title: Dynamically get a running container id/name created by docker run command
body: <p>So I'm trying to run the following shell script which requires the container id/name of the container (in which the script would be run) dynamically.</p>
  
  <p>One way could be to do <strong>docker ps</strong> and then getting the Container Id, but that won't be dynamic.</p>
  
  <p>So is there a way to do this dynamically?</p>
  
  <pre><code>#!/bin/bash
  docker exec &lt;container id/name&gt; /bin/bash -c "useradd -m &lt;username&gt; -p &lt;password&gt;"
  </code></pre>