A
A
Arris2022-02-06 21:56:36
Docker
Arris, 2022-02-06 21:56:36

How to convince docker to create directories with correct permissions?

We have such a tool tyrrrz/discordchatexporter (but I think it doesn't depend on the tool at all, because the problem arises at a different level)... The tool is engaged in exporting the discord channel to HTML/JSON, etc.

It doesn't really matter what she does, because the problem, apparently, is again on the docker side.

So, what's the catch:

I launch the tool like this:

[email protected]:~$ docker run --rm --user 1000:1000 -v /home/arris/out/:/app/out/ tyrrrz/discordchatexporter:latest export <параметры>


If the directory /home/arris/out/ (or any other) exists and the user has 1000:1000 rights to it, then everything is fine, the export works without errors, the files have the correct rights and in general everyone is happy.

But if the target directory DOES NOT EXIST - docker (?) happily creates it, and then the export fails with Permission Denied. Because suddenly

[email protected]:~$ ls -la /home/arris/out/
total 8
drwxr-xr-x 2 root  root  4096 Feb  6 21:46 .
drwxr-xr-x 9 arris arris 4096 Feb  6 21:46 ..


PS And if you omit --user 1000:1000 - then everything is perfectly created, exported, but the export result - all files belong to the root. Which is also not what you want.

CHADNT or how to convince docker to create directories with correct permissions?

PS The developer of the tool is also not a real welder and also does not know the answer.
PPS
[email protected]:~$ id arris

uid=1000(arris) gid=1000(arris) groups=1000(arris), ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-02-07
@Arris

1. Use volume
2. Either make sure that the directory exists: mkdir -p <directory> && docker ...
3. Or assign the correct owner of the directory:

mkdir -p <directory> && chown 1000:1000 <directory> && docker ...

If this is not run by root, in step 3 you will need to use sudo.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question