How to give non-root user permission to make and give access to a folder in a Dockerfile


I am trying to create/permission to folders using a non-root user using an image from ubi8/ubi-minimal redhat.

Here are two questions:

  1. Make a folder: Another way to give non-user permission to create folders and give permission to folders. I have searched a bit. Could be possible under the RUN command after it installs all package with microdnf?
  2. Give access: Will RUN chmod -R 777 /app is not best practice and best to do RUN chown -R $USER:$USER /app?

Here is my Dockerfile which I repeat chown a bit for permission.


ENV USER=appuser

RUN microdnf update -y 
    && rm -rf /var/cache/yum 
    && microdnf install gcc wget tar gzip make zlib-devel findutils bzip2-devel openssl-devel ncurses-devel 
       sqlite-devel libffi-devel xz-devel which shadow-utils 
    && microdnf clean all ;
    useradd -m $USER

RUN chown -R $USER:$USER /opt

RUN mkdir -p /app
RUN chown $USER /app
COPY  . /app/

RUN chown -R $USER:$USER /app

Source: Docker Questions

Categorised as docker, dockerfile, redhat, redhat-containers Tagged , , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us