I've created a custom user using my Dockerfile. Here is my Dockerfile:
FROM python:3.7-alpine3.10
# Make /opt/ working directory in docker container.
WORKDIR /opt/
# Copy source code to image
COPY app app
# Create a user
RUN adduser -S my_user
# Change owner and permissions
RUN chown -R my_user /opt/
RUN chmod -R 755 /opt/
USER my_user
# Start main.py script after container is up.
ENTRYPOINT python app/main.py
In my script, I'm creating a file in the container's /opt/app/
directory, and this directory is mounted at host's /var
in docker-compose using /var/log/app:/opt/app/:z
.
When I run the container as root (without creating any users in Dockerfile), this works perfectly but using custom user, I'm getting [Error 13] permission denied
in my script.
I've also changed the owner of the directory in Docker file and also given the permissions as 755
. So what am I missing here?
Note: I've referred to a similar question but it didn't work for me: Cannot create directory. Permission denied inside docker container