title: Unable to get any Docker Entrypoint from script working without continuous restarts
body: <p>I'm having trouble understanding or seeing some working version of using a bash script as an Entrypoint for a Docker container. I've been trying numerous things for about 5 hours now.</p>
  
  <p>Even from this <a href="https://success.docker.com/article/use-a-script-to-initialize-stateful-container-data" rel="nofollow noreferrer">official Docker blog</a>, using a bash-script as an entry-point still doesn't work.</p>
  
  <p>Dockerfile</p>
  
  <pre><code>FROM debian:stretch
  COPY docker-entrypoint.sh /usr/local/bin/
  RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
  ENTRYPOINT ["docker-entrypoint.sh"]
  CMD ["postgres"]
  </code></pre>
  
  <p>docker-entrypoint.sh</p>
  
  <pre><code>#!/bin/bash
  set -e
  
  if [ "$1" = 'postgres' ]; then
      chown -R postgres "$PGDATA"
  
      if [ -z "$(ls -A "$PGDATA")" ]; then
          gosu postgres initdb
      fi
  
      exec gosu postgres "$@"
  fi
  
  exec "$@"
  </code></pre>
  
  <p>build.sh</p>
  
  <pre><code>docker build -t test .
  </code></pre>
  
  <p>run.sh</p>
  
  <pre><code>docker service create \
  --name test \
  test
  </code></pre>
  
  <p>Despite many efforts, I can't seem to get Dockerfile using an Entrypoint as a bash script that doesn't continuously restart and fail repeatedly.</p>
  
  <p>My understanding is that <code>exec "$@"</code> was suppose to keep the container form immediately exiting, but I'm not sure if that's dependent some other process within the script failing.</p>
  
  <p>I've tried using a <code>docker-entrypoint.sh</code> script that simply looked like this:</p>
  
  <pre><code>#!/bin/bash
  
  exec "$@"
  </code></pre>
  
  <p>And since that also failed, I think that rules out something else going wrong inside the script being the cause of the failure.</p>
  
  <p>What's also frustrating is there are no logs, either from <code>docker service logs test</code> or <code>docker logs [container_id]</code>, and I can't seem to find anything useful in <code>docker inspect [container_id]</code>.</p>
  
  <p>I'm having trouble understanding everyone's confidence in <code>exec "$@"</code>. I don't want to resort to using something like <code>tail -f /dev/null</code> or using a command at <code>docker run</code>. I was hoping that there would be some consistent, reliable way that a <code>docker-entrypoint.sh</code> script could reliably used to start services that I could run with <code>docker run</code> as well for other things for services, but even on Docker's official blog and countless questions here and blogs from other sites, I can't seem get a single example to work.</p>
  
  <p>I would really appreciate some insight into what I'm missing here.</p>