title: unable to run docker as non-root user?
body: <p>I have tried this <a href="https://stackoverflow.com/questions/29891010/how-to-run-docker-image-as-a-non-root-user">post</a> and it did NOT help.</p>
  
  <p>I have created <code>jenkins</code> user and add it to docker group.</p>
  
  <p>I have also switched the user in dockerFile (see below).</p>
  
  <p>I started the container as following</p>
  
  <p><code>docker run -u jenkins -d -t -p 8080:8080 -v /var/jenkins:/jenkins -P docker-registry:5000/bar/helloworld:001</code></p>
  
  <p>The container starts fine. but when I look at the process, this is what I have</p>
  
  <pre><code>root     13575     1  1 09:34 ?        00:05:56 /usr/bin/docker daemon -H fd://
  root     28409 13575  0 16:13 ?        00:00:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8080 -container-ip 172.17.0.2 -container-port 8080
  </code></pre>
  
  <p>The first one is daemon. so I guess it is ok to be root.
  but the second one (which I have switched to jenkins user by issuing <code>sudo su jenkins</code>) is showing <code>root</code>. I started the docker as jenkins user. why this process belongs to root?</p>
  
  <p>Here is my dockerfile</p>
  
  <pre><code>#copy jenkins war file to the container
  ADD http://mirrors.jenkins-ci.org/war/1.643/jenkins.war /opt/jenkins.war
  RUN chmod 644 /opt/jenkins.war
  ENV JENKINS_HOME /jenkins
  
  
  RUN useradd -d /home/jenkins -m -s /bin/bash jenkins
  USER jenkins
  ENV HOME /home/jenkins
  WORKDIR /home/jenkins
  
  # Maven settings
  RUN mkdir .m2
  ADD settings.xml .m2/settings.xml
  
  ENTRYPOINT ["java", "-jar", "/opt/jenkins.war"]
  EXPOSE 8080
  CMD [""]
  </code></pre>
  
  <h2>EDIT2</h2>
  
  <p>I am certain the container the running. I could attach to the container.
  I can also browse through web-ui of jenkins, which is only possible if the container has started without errors (jenkins run inside the container)</p>
  
  <p>Here is my command inside the container</p>
  
  <pre><code>ps -ef | grep java
  jenkins      1     0  7 19:29 ?        00:00:28 java -jar /opt/jenkins.war
  
  ls -l /jenkins
  drwxr-xr-x  2 jenkins jenkins 4096 Jan 11 18:54 jobs
  </code></pre>
  
  <p>But from the host file system, I see that the newly created "jobs" directory shows as user "admin"</p>
  
  <pre><code>ls -l /var/jenkins/
  drwxr-xr-x  2 admin admin 4096 Jan 11 10:54 jobs
  </code></pre>
  
  <p>Inside the container, the jenkins process (war) is started by "jenkins" user. Once the jenkins starts, it writes to host file system under "admin" user.</p>
  
  <p>Here is my entire dockerFile (NOTE: I don't use the one from here)</p>
  
  <pre><code>FROM centos:7
  RUN yum install -y sudo
  RUN yum install -y -q unzip
  RUN yum install -y -q telnet
  RUN yum install -y -q wget
  RUN yum install -y -q git
  
  ENV mvn_version 3.2.2
  
  # get maven
  RUN wget --no-verbose -O /tmp/apache-maven-$mvn_version.tar.gz http://archive.apache.org/dist/maven/maven-3/$mvn_version/binaries/apache-maven-$mvn_version-bin.tar.gz
  # verify checksum
  RUN echo "87e5cc81bc4ab9b83986b3e77e6b3095 /tmp/apache-maven-$mvn_version.tar.gz" | md5sum -c
  
  # install maven
  RUN tar xzf /tmp/apache-maven-$mvn_version.tar.gz -C /opt/
  RUN ln -s /opt/apache-maven-$mvn_version /opt/maven
  RUN ln -s /opt/maven/bin/mvn /usr/local/bin
  RUN rm -f /tmp/apache-maven-$mvn_version.tar.gz
  ENV MAVEN_HOME /opt/maven
  
  # set shell variables for java installation
  ENV java_version 1.8.0_11
  ENV filename jdk-8u11-linux-x64.tar.gz
  ENV downloadlink http://download.oracle.com/otn-pub/java/jdk/8u11-b12/$filename
  
  # download java, accepting the license agreement
  RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -O /tmp/$filename $downloadlink
  
  # unpack java
  RUN mkdir /opt/java-oracle &amp;&amp; tar -zxf /tmp/$filename -C /opt/java-oracle/
  ENV JAVA_HOME /opt/java-oracle/jdk$java_version
  ENV PATH $JAVA_HOME/bin:$PATH
  
  # configure symbolic links for the java and javac executables
  RUN update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 20000 &amp;&amp; update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 20000
  
  # copy jenkins war file to the container
  ADD http://mirrors.jenkins-ci.org/war/1.643/jenkins.war /opt/jenkins.war
  RUN chmod 644 /opt/jenkins.war
  ENV JENKINS_HOME /jenkins
  
  #RUN useradd jenkins
  #RUN chown -R jenkins:jenkins /home/jenkins
  #RUN chmod -R 700 /home/jenkins
  #USER jenkins
  
  RUN useradd -d /home/jenkins -m -s /bin/bash jenkins
  #RUN chown -R jenkins:jenkins /home/jenkins
  USER jenkins
  ENV HOME /home/jenkins
  WORKDIR /home/jenkins
  
  # Maven settings
  RUN mkdir .m2
  ADD settings.xml .m2/settings.xml
  USER root
  RUN chown -R jenkins:jenkins .m2
  USER jenkins
  
  ENTRYPOINT ["java", "-jar", "/opt/jenkins.war"]
  EXPOSE 8080
  CMD [""] 
  </code></pre>