<pre><code>  CMD ['sleep', 100000] 
</code></pre>

<p>gets stuck and becomes unresponsive for <strong>ctrl + c.</strong> </p>

<p>Any suggestions? </p>

<p>The issue is when the CMD is not running properly, it is usually easier to <strong>exec --it</strong> into the server and do those things manually to get them up and running properly. </p>

<p>Without a <strong>CMD</strong>, run will exit, and therefore exec won't be possible. </p>

<p>I've used sleep for this, but i saw a ping, but ping is not default in ubuntu 18, and perhaps there are better ways than installing it for this simple purpose. </p>

mjs
<p>You can provide an alternate command when you run the image.  That can be anything you want -- a debugging command, an interactive shell, an alternate process.</p>

<pre class="lang-sh prettyprint-override"><code>docker run --rm myimage ls -l /app
docker run --rm -it myimage bash
# If you're using Compose
docker-compose run myservice bash
</code></pre>

<p>This generally gets around the need to "keep the container alive" so that you can <code>docker exec</code> into it.  Say you have a container command that doesn't work right:</p>

<pre class="lang-sh prettyprint-override"><code>CMD ["my_command", "--crash"]
</code></pre>

<p>Without modifying the Dockerfile, you can run an interactive shell as above.  When you get a shell prompt, you can run <code>my_command --crash</code>, and when it crashes, you can look around at what got left behind in the filesystem.</p>

<p>It's important that <code>CMD</code> be a complete command for this to work.  If you have an <code>ENTRYPOINT</code>, it needs to use the JSON-array syntax and it needs to run the command that gets passed to it as command line parameters (often, it's a shell script that ends in <code>exec "$@"</code>).</p>
