How I can create user in dockerfile and applied permission to folder

I am creating docker image with user. Also, I have applied all the permission to specific folder in which my code has been located.
Here is my Dockerfile

FROM Ubuntu:latest
RUN useradd -r -d /flask_dir -s /bin/bash -c “Docker image user” flask_user
COPY flask_dir /flask_dir
RUN chown -R flask_user: /flask_dir
RUN chmod 777 /flask_dir
EXPONSE 5000
USER flask_user
ENTRYPOINT [“./entrypoint.sh”]
CMD [“start”]

In flask_dir I have one folder called Certificates. At the time of running it creates certificates and store them into Certificates directory but I am not able to read that file it says me permission denied. But when I run my image with root user it works fine.

Does anyone knows what is wrong with custom user.

Thanks!

I just solved a similar problem. In my case signalfx-agent didn’t have permission to create *.log file when it was run as USER signalfx-agent and my first attempt was the same as yours.

In my case helped to change ownership of the executed file (was root:root)
RUN chown signalfx-agent:signalfx-agent /usr/lib/signalfx-agent/bin/signalfx-agent
but I see you are doing it for whole directory (including main executable), am I right?

Thanks! Yes, I resolved the same by assign appropriate permission to both the user. I mean one which is running inside docker and another one which is running in host. I forget that I have bound the volume.