title: How to make a docker entrypoint run as non-root for some particular commands only
body: <p>My PHP image entry point is something like below. The entrypoint runs as <strong>root</strong> and it is necessary in my case . So any command I run on my container runs as root. For some particular command I want to run it as another user e.g when someone try to execute <code>docker exec -it php composer install</code> composer should run as another user set in entrypoint. when someone try to execute <code>docker exec -it php drush status</code> drush should run as another user set in entry point. Probably a if or switch statement inside entrypoint can help me. I was trying something like this <a href="https://unix.stackexchange.com/questions/476155/how-to-pass-multiple-parameters-to-su-user-c-command">https://unix.stackexchange.com/questions/476155/how-to-pass-multiple-parameters-to-su-user-c-command</a> but passing parameter with double dash (--) breaks some command.   </p>
  
  <p>Dockerfile</p>
  
  <pre><code>COPY entrypoint.sh /
  ENTRYPOINT ["/entrypoint.sh"]
  CMD ["php-fpm"]
  </code></pre>
  
  <p>entrypoint.sh</p>
  
  <pre><code>#!/bin/sh
  
  set -e
  
  # first arg is `-f` or `--some-option`
  if [ "${1#-}" != "$1" ]; then
      set -- php-fpm "$@"
  fi
  
  exec "$@"
  </code></pre>