On Linux I want to run my program in docker container and have 1 directory bound (mounted?) read-write between host and container. Further I want the program running in container run as a normal user. I have a problem with that "normal user" part. I create user in Dockerfile:
# Add in non-root user
ENV UID_OF_DOCKERUSER 1001
RUN useradd -m -s /bin/bash -g users -u ${UID_OF_DOCKERUSER} dockerUser
RUN chown -R dockerUser:users /home/dockerUser && chown dockerUser:users /opt
USER dockerUser
COPY --chown=dockerUser:users container_startup.sh /opt/container_startup.sh
ENTRYPOINT ["/opt/container_startup.sh"]
When starting container I mount local directory in such way:
docker run -it --rm -v ./test:/test:rw myimage
Now files can be shared between host user account and container's root account. If I use dockerUser
account, then it can't read files in shared directory and if it creates anything there, it can't be read by host user account (different uid is given).
What to do to make the volume inside container be owned by dockerUser
?