title: Why is Docker entrypoint script not executed in detached mode?
body: <p>Assume this simple Dockerfile: </p>
  
  <pre><code>FROM debian:stretch
  COPY entrypoint.sh /usr/local/bin/entrypoint.sh
  RUN chmod a+x /usr/local/bin/entrypoint.sh
  ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
  </code></pre>
  
  <p>And entrypoint.sh looks like this:</p>
  
  <pre><code>#!/bin/bash
  echo yyyyyyyyyyyyyyy
  exec "$@"
  </code></pre>
  
  <p>Now if I build the image and create the container in foreground, the entrypoint script is executed:</p>
  
  <pre><code>$ docker build . -t mytest
  [...]
  $ docker run --rm -it mytest /bin/bash
  yyyyyyyyyyyyyyy
  root@3e3d7290b09c:/#
  </code></pre>
  
  <p>But if I create the container in detached mode, it is not executed:</p>
  
  <pre><code>$ docker run --rm -d -it mytest /bin/bash
  f8e72a222c5194f61843569ae76798bb09736fa4205b93e484f11de32df4db64
  </code></pre>
  
  <p>Why is that? Or, more importantly, how can I create a detached container, where the entrypoint script is executed?</p>