I've got a Docker image which generates log-like files when errors occur. I've mounted the directory it writes to to my host machine with a bind mount. However, the created files are owned by root
. Though my user account has root privileges, it is tedious to run chown
and chgrp
after every run of the container in order to inspect the files.
Is there a way to have the container set the owner and group of the files to that of the user who ran the container?
For some context, here's a toy example I created:
Dockerfile
FROM debian
WORKDIR /root
VOLUME /root/output
COPY run.sh /root/
ENTRYPOINT ["./run.sh"]
run.sh
#!/bin/bash
echo hello > output/dump
My execution command is
docker run -v $PWD/output:/root/output test