2 years ago

#52701

test-img

Bebe

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.

FROM registry.access.redhat.com/ubi8/ubi-minimal

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
USER $USER
WORKDIR /app
COPY  . /app/

RUN chown -R $USER:$USER /app

docker

dockerfile

redhat

redhat-containers

0 Answers

Your Answer

Accepted video resources