dockerdocker-composedockerfileself-hostingfile-sharing

Issues With File Sharing on Docker (Ubuntu)


I'm trying to get vaultwarden set up and working using docker.

I followed the docker install on dockers page and then followed this tutorial for vaultwarden https://www.youtube.com/watch?v=v_7vJDwGWug.

Everything seems fine when I run the command:

docker-compose -d up

from the video to run the .yml file that contains:

version: "3.9" 
services:   
    vaultwarden:     
        image: vaultwarden/server:latest     
        restart: unless-stopped     
        volumes:       
            - /opt/vw:/data     
        ports:       
            - "80:80"
            - "3012:3012"

However, when I run:

ls /opt/vw

It shows me that nothing has been created within that folder and there should be files created within there.

Doing a bit more digging I checked the docker logs for the container and found some errors. These errors were:

[INFO] No .env file found.
 
[2023-03-18 17:07:53.347][vaultwarden::util][ERROR] Can't create 'data/rsa_key.pem': Permission denied
[2023-03-18 17:07:53.347][vaultwarden][ERROR] Error creating keys, exiting...

I don't know what's going on with the "No .env file found" but the other errors shows me that it doesn't have high enough permission to create files and folders within the specified volume.

I figured this was an issue with the file sharing as I had read something about it before, so I went to dockers settings, then resources, then file sharing and tried to add the directories (I tried /opt, /, /home, /opt/vw, and /data) into there so it could access them. I expected this to result in the vaultwarden container to have permission to create the files. Unfortunately that did not seem to work as I was still getting errors.

I went to dockers page about how to enable file sharing, https://docs.docker.com/desktop/faqs/linuxfaqs/#how-do-i-enable-file-sharing, to figure out how to file share and this is so far where I've ended up stuck.

I'm at a loss because it seems that the only thing this page tells me is to make sure that /etc/subgid and /etc/subuid exist and output:

MyUser:100000:65536

Both /etc/subgid and /etc/subuid exist and output this when doing:

cat /etc/(subgid or subuid)

Do I need to maybe change it to have ID 0 where instead it outputs:

MyUser:1000:65536

Or is there a different ID for root? Any help on this issue would be greatly appreciated as I've spent well over 5 hours trying to fix this one issue.


Solution

    1. Update the permission of /opt/vw to 777 to verify if that works.
    chmod 777 /opt/vw
    
    1. Check the user with which the process is running in the vaultwarden container. It is possible that the internal process started by the main script is running by a non-root user that actually doesn't have access to write in the directory.
    docker top <container-name>
    
    1. Update the permissions of the directory based on that user, by updating the entrypoint of the container.
    entrypoint: 
     - "sh"
     - "-c"
     - "chown <desired-user>:<desired-group> /data && <your-script.sh or whatever you want to run>"