title: How to run only one thing as root in docker
body: <p>I'm trying to create a Dockerfile which runs as non-root user.
  When i building this all works fine, but nginx cannot write the log file because it dosen't have enough permissions. Can I, when building a Docker, give root permissions only for nginx?</p>
  
  <p>I'm trying chmod, chown for blocked directories. Doesn't work</p>
  
  <pre><code>FROM php:7.1-fpm-alpine
  
  RUN apk add --no-cache shadow
  
  RUN apk add --no-cache --virtual .ext-deps \
          openssl \
          unzip \
          libjpeg-turbo-dev \
          libwebp-dev \
          libpng-dev \
          freetype-dev \
          libmcrypt-dev \
          imagemagick-dev \
          nodejs-npm \
          nginx \
          git \
          inkscape
  
  # imagick
  RUN apk add --update --no-cache autoconf g++ imagemagick-dev libtool make pcre-dev \
      &amp;&amp; pecl install imagick \
      &amp;&amp; docker-php-ext-enable imagick \
      &amp;&amp; apk del autoconf g++ libtool make pcre-dev
  
  # Install Blackfire
  RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
      &amp;&amp; curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
      &amp;&amp; tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \
      &amp;&amp; mv /tmp/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
      &amp;&amp; printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" &gt; $PHP_INI_DIR/conf.d/blackfire.ini
  
  RUN apk add -y icu-dev \
      &amp;&amp; docker-php-ext-configure intl \
      &amp;&amp; docker-php-ext-install intl
  
  RUN docker-php-ext-configure pdo_mysql &amp;&amp; \
      docker-php-ext-configure opcache &amp;&amp; \
      docker-php-ext-configure exif &amp;&amp; \
      docker-php-ext-configure pdo &amp;&amp; \
      docker-php-ext-configure zip &amp;&amp; \
      docker-php-ext-configure gd \
      --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-webp-dir=/usr/include --with-freetype-dir=/usr/include &amp;&amp; \
      docker-php-ext-configure sockets &amp;&amp; \
      docker-php-ext-configure mcrypt
  
  RUN docker-php-ext-install pdo zip pdo_mysql opcache exif gd sockets mcrypt &amp;&amp; \
      docker-php-source delete
  
  RUN ln -s /usr/bin/php7 /usr/bin/php &amp;&amp; \
      curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer &amp;&amp; \
      mkdir -p /run/nginx
  
  COPY ./init.sh /
  COPY ./default.conf /etc/nginx/conf.d/default.conf
  COPY ./.env /
  RUN chmod +x /init.sh
  
  
  EXPOSE 80
  
  RUN addgroup -g 1001 node \
      &amp;&amp; adduser -u 1001 -G node -s /bin/sh -D node
  
      ARG UID=1001
      ARG GID=1001
      ENV UID=${UID}
      ENV GID=${GID}
  
  RUN usermod -u $UID node \
      &amp;&amp; groupmod -g $GID node
  
  
  RUN chown 1001:1001 /var/lib/nginx -R
  RUN mkdir -p /var/tmp/nginx
  RUN chown 1001:1001 /var/tmp/nginx -R
  
  USER node
  
  ENTRYPOINT [ "/init.sh" ]
  </code></pre>