title: Docker Entrypoint not running as root on jupyterhub
body: <p>We are trying to run a docker entrypoint as root in a docker image used by our jupyterhub for the single user servers. We need root to add a host to access an internal git registry from within a single user jupyter notebook server on a jupyterhub running on K8S by it's domain.</p>
  
  <p>We already tried adding the domain to the <code>/etc/hosts</code> file in the docker image which is loaded for the single user servers by our jupyterhub in a docker-entrypoint script (code can be seen at the bottom).</p>
  
  <p>However we get a permission denied when trying to add the host.
  The printouts also show why:</p>
  
  <p>Locally, the first whoami shows <code>root</code> , as we expected.
  On the jupyter notebook started in a pod by our jupyterhub (running on K8s) however, the first printout already shows <code>jovyan</code>.</p>
  
  <p>The same effect can be seen when directly printing out whoami in the entrypoint in the Dockerfile like this:</p>
  
  <pre><code>ENTRYPOINT ["sh", "-c", "echo $(whoami)"]
  </code></pre>
  
  <p>Meaning that it is the whole entrypoint, that does not get executed as root but the user is somehow switched beforehand.</p>
  
  <p>Can we prevent this behaviour or is there a good workaround?</p>
  
  <p>Any help appreciated, thank you in advance!
  PS:
  Additionally, when we try to run <code>exec su - "jovyan"</code> in the entrypoint-script on the jupyterhub, we are getting the error, that the su command has to be run from a terminal. Locally it works without problems.
  <br/><br/><br/><br/></p>
  
  <hr>
  
  <p>Code of docker-entrypoint script (just for reference):</p>
  
  <p><strong>Dockerfile:</strong></p>
  
  <pre><code>FROM jupyter/datascience-notebook:1145fb1198b2
  WORKDIR /usr/src/app
  
  USER root
  
  ...
  
  COPY aai-entrypoint.sh /usr/src/app/aai-entrypoint.sh
  RUN chmod +x /usr/src/app/aai-entrypoint.sh
  
  ENTRYPOINT ["sh", "/usr/src/app/my-entrypoint.sh"]
  CMD ""
  </code></pre>
  
  <p>We added the empty CMD to overwrite the CMD of the jupyter base-notebook</p>
  
  <p><strong>my-entrypoint.sh:</strong></p>
  
  <pre><code>#!/bin/bash
  echo $(whoami)
  echo "xx.xxx.xxx   our.domain.com" &gt;&gt; /etc/hosts
  echo "test"
  exec su - "jovyan"
  echo $(whoami)
  
  # to not overwrite the entrypoint of the jupyter/base-notebook
  # see https://github.com/jupyter/docker-stacks/blob/master/base-notebook/Dockerfile
  exec tini -g -- "start-notebook.sh"
  </code></pre>