In this small blog post I want to show how you can manage files inside different docker volumes with different file ownerships via the filebrowser container.
filebrowser provides a file managing interface within a specified directory and it can be used to upload, delete, preview, rename and edit your files. It allows the creation of multiple users and each user can have its own directory. It can be used as a standalone app.
Some containers store their data under different user and group affiliations and that can be a problem for the default configured filebrowser container. The filebrowser container uses the owner-id 1000
and group-id 1000
for writing, reading files. If for some reason you want to manage the volume content of a different container but the files owner-id
and group-id
are not 1000
, filebrowser can not write or read these files.
If you are unsure what owner-ids and group-ids are used in a docker volume you can check it via following command on your host system:
ls -lan /path/to/docker-volume
sudo
rightsIn the following steps I install the filebrowser application as a docker container itself. For that I am using a docker compose
Create a docker-compose.yml
via nano
nano docker-compose.yml
Now paste the following content into the nano
editor:
In my example I have three different folders I want to access via the filebrowser docker myfolder1
, myfolder2
and myfolder3
.
Please change the
/path/to
portions of the file paths !!!
services:
filebrowser:
volumes:
- /path/to/myfolder1:/srv/myfolder1
- /path/to/myfolder2:/srv/myfolder2
- /path/to/myfolder3:/srv/myfolder3
- /path/to/filebrowserstack/filebrowser.db:/database/filebrowser.db
- /path/to/filebrowserstack/.filebrowser.json:/.filebrowser.json
- /path/to/filebrowserstack/chown-script.sh:/chown-script.sh
user: 0:0
ports:
- 8080:80
image: filebrowser/filebrowser
Save the changes via Ctrl+O
and close the nano
editor with Ctrl+X
.
Now create filebrowser.db
and .filebrowser.json
for the filebrowser docker container (these files are used by filebrowser to save persistent data):
Please change the
/path/to
portions of the file paths !!!
sudo touch /path/to/filebrowserstack/filebrowser.db
sudo tee /path/to/filebrowserstack/.filebrowser.json <<EOF
{
"port": 80,
"baseURL": "",
"address": "",
"log": "stdout",
"database": "/database/filebrowser.db",
"root": "/srv"
}
EOF
Create a custom script for chown
operations (chown-script.sh
):
myfolder1
have ownership 1001:1001
myfolder2
have ownership 33:33
myfolder3
have ownership 1000:1000
Please change the
/path/to
portions of the file paths !!!
sudo tee /path/to/filebrowserstack/chown-scripts.sh <<EOF
#!/bin/sh
FILE=\$1
if [[ "\$FILE" == *"myfolder1"* ]]; then
chown 1001:1001 "\$FILE"
elif [[ "\$FILE" == *"myfolder2"* ]]; then
chown 33:33 "\$FILE"
elif [[ "\$FILE" == *"myfolder3"* ]]; then
chown 1000:1000 "\$FILE"
fi
EOF
sudo chmod +x /path/to/filebrowserstack/chown-script.sh
Now deploy the filebrowser container via the docker-compose.yml
file we have created in step 1:
sudo docker compose -f /path/to/docker-compose.yml up -d
Now login into the web interface of the filebrowser container: https://<IP-address_of_host_system>:8080
and go to Settings -> Global Settings -> Command Runner
.
Put the following code intor After Copy
, After Rename
, After Save
and After Upload
text area:
./chown-script.sh "$FILE"
At the end of the site click on UPDATE
Button to save.