Docker Community Forums

Share and learn in the Docker community.

Remove a directory created by a container (permission issue)

Hi,
I run a code inside a container that creates an output folder and many other folders inside, I mounted the data into a directory using -v.
The output folder is created but I can’t remove it as it belongs to the root.

I added my user to the dockerfile as following:

RUN addgroup --gid 1001 uname
RUN adduser --disabled-password --gecos "" --force-badname --gid 1001 --uid 1002 uname
USER uname

After that, I could remove the output folder, but I can’t write on it.
What shall I add to the dockerfile or when I run the container to give all permission to my user?

Thanks

Change the owner of all the files on the directory to your used ID within the container running as root, then exit the container and remove the directory.

docker run --rm -v /target/new_directory 990210oliver/mycc.docker:v1 chown -R (id -un):(id -un) /target/new_directory
exit
rm -rf $HOME/new_directory

Thanks.
I don’t have the root privilege.
Is there an easier way to do it? I need to remove the folder after each execution of the code.