evan-buss / openbooks

Search and Download eBooks
https://evan-buss.github.io/openbooks/
MIT License
1.77k stars 57 forks source link

Unable to start container when using bind mounted volumes (mkdir and permissions issues) #161

Open 99linesofcode opened 5 months ago

99linesofcode commented 5 months ago

When using bind mounts, there are a couple of things that go wrong.

Firstly, if the directory doesn't exist it is created by the root user, and permissions are not changed to the user and group id's passed to docker run or docker-compose.yaml. This causes os.mkdirAll to fail when it attempts to create the /books directory. This is slightly odd since it will create all the parent folders on the host machine (owned by root) but then fails to create the last folder due to permission issues?

Secondly, if the folder does exist, an error is thrown: `Error response from daemon: error while creating mount source path '/home/USERNAME/books': mkdir /home/USERNAME/books: file exists. Makes sense, since the directory is already mounted into the container.

The above seems to happen with other containers as well. edit: yup, this is cause by combining docker bind mounts and fuse filesystems. Please ignore the above.

I would expect openbooks to either create the folders with the correct file ownership settings OR leave things alone if the directories are already present.

Example docker-compose.yaml:

services:
  openbooks:
    image: evanbuss/openbooks
    user: 1000:1000
    volumes:
      - $HOME/books:/books/books
    ports:
      - 8080:80
    command: -s irc.irchighway.net:9999 --persist -n <REDACTED> -u <REDACTED>

edit: typo