title: How to run Apache as non-root user?
body: <p>I'm building an image from the following Dockerfile and following command <code>docker build --rm -f &quot;Dockerfile&quot; -t non_root_image_plz_work .</code>:</p>
  <p><strong>DockerFile</strong></p>
  <pre><code>FROM node:14.7.0-buster-slim AS apache_for_selenium
  
  # Create non-root group and user
  RUN addgroup --system shared-folder \
  &amp;&amp; adduser --system --home /var/cache/shared-folder --group shared-folder --uid 1001
  
  # Make Port accessable 
  EXPOSE 80/tcp
  
  # Set Node env.Name
  ENV NODE_ENV=dev 
  
  RUN apt-get -qq update &amp;&amp; apt-get -qq install -y --no-install-recommends nano git openssl bash musl curl apache2 apache2-utils systemd &amp;&amp; \
      systemctl enable apache2 &amp;&amp; npm config set registry http://localhost:5000/repository/repo &amp;&amp; \
      npm i -g pm2 serve &amp;&amp; mkdir /usr/share/shared-folder
  
  RUN ln -sf /dev/stdout /var/log/apache2/access.log &amp;&amp; \
      ln -sf /dev/stderr /var/log/apache2/error.log    
  
  WORKDIR /usr/share/shared-folder 
  
  COPY . /usr/share/shared-folder/
  
  RUN npm install &amp;&amp; npm cache clean --force &amp;&amp; npm cache verify &amp;&amp; \
      rm /var/www/html/index.html &amp;&amp; \
      ln -s /usr/share/shared-folder/mochawesome-report /var/www/html/mochawesome-report &amp;&amp; \
      chown www-data -R /var/www/html/mochawesome-report &amp;&amp; chgrp www-data -R /var/www/html/mochawesome-report 
  
  VOLUME /usr/share/shared-folder/mochawesome-report
  
  USER 1001
  
  CMD [ &quot;sh&quot;, &quot;-c&quot;, &quot;service apache2 start ; pm2-runtime process.yml --no-daemon&quot; ]
  </code></pre>
  <p>When I try to run the image using <code>docker run non_root_image_plz_work</code>, I get the following error:</p>
  <p><strong>Error after running <code>docker run</code> command:</strong>
  Starting Apache httpd web server: apache2 failed!
  The apache2 configtest failed. ... (warning).
  Output of config test was:
  mkdir: cannot create directory '/var/run/apache2': Permission denied
  chown: changing ownership of '/var/lock/apache2.3FGoa8Y71E': Operation not permitted</p>
  <p>It seems to be a permissions issue, as if I'm not properly running the container as a non-root user. Any suggestions on how I can get the container to run properly as a non-root user?</p>
  <p><strong>Note:</strong> I used a dummy registry in the Dockerfile for I don't want to show the actual registry, thanks</p>