Calibre Web: home in-browser online-library with Nextcloud storage and Moon+ Reader on Android
Tags: android, docker
Published: 2020-01-09 09:35:10

---
title: Calibre Web: home in-browser online-library with Nextcloud storage and Moon+ Reader on Android
published: true
date: 2020-01-07 09:51:57 UTC
tags: Android,Docker
canonical_url: https://rtfm.co.ua/en/calibre-web-home-in-browser-online-library-with-nextcloud-storage-and-moon-reader-on-android/
---


![](https://rtfm.co.ua/wp-content/uploads/2019/12/Calibre_logo_3.png)I’m using [Calibre](https://calibre-ebook.com/) for my e-books library management for many years, but until today always used its desktop version.

A couple of days ago I found the [Calibre Web](https://github.com/janeczku/calibre-web) project – the same library, working with the same database, but accessible via a browser.

The idea is to move away from storing books in Google Books and using its e-book reader on mobile and via a browser but still to be able to access my library from anywhere and to have have a book’s reading position synchronization ability, as it is in the Google Books mobile and browser readers.

So, now I have my library itself is stored in a Nextcloud (see the [Nextcloud: running in Docker Compose on Debian with Let’s Encrypt SSL post](https://rtfm.co.ua/en/nextcloud-running-in-docker-compose-on-debian-with-lets-encrypt-ssl/)), and I’ll use the [Moon+ Reader](https://play.google.com/store/apps/details?id=com.flyersoft.moonreader&hl=en) application on my Android devices as it can synchronize read position via [WebDAV](https://en.wikipedia.org/wiki/WebDAV).

Also, you can use Google Drive as a storage backend for Calibre Web, read the [docs](https://github.com/janeczku/calibre-web/wiki/Configuration#using-google-drive-integration).

In this post we will:

- run a Calibre Web instance in Docker – a web interface for a library
- will mount a directory from the Nextcloud with Calibre’s library
- and will use WebDAV from our phone to connect to the Nextcloud using Moon+ Reader

### NGINX, Let’s Encrypt

NGINX + Let’s Encrypt set up already described in the [Bitwarden: an organization’s password manager self-hosted version installation on an AWS EC2](https://rtfm.co.ua/en/bitwarden-an-organizations-password-manager-self-hosted-version-installation-on-an-aws-ec2/#The_hosts_set_up) post.

### Calibre Web start

Check the library’s directory under Nextcloud which will be used by our Calibre Web:

```
$ ll /data/nextcloud/app/data/setevoy/files/Books/CALIBRE/ | head
total 1212
drwxr-xr-x  3 www-data www-data   4096 Dec 13 07:53 A. A. Orlov
drwxr-xr-x  7 www-data www-data   4096 Dec 13 07:53 A. Avramienko
drwxr-xr-x  3 www-data www-data   4096 Dec 13 07:55 A. Bielash
drwxr-xr-x  3 www-data www-data   4096 Dec 13 07:55 Adol_f Gitlier
drwxr-xr-x  3 www-data www-data   4096 Dec 13 07:55 Al_bier Kamiu
...
```

Run a Docker container with Calibre, mount the library’s directory inside as `/books`:

```
$ docker run -ti --name books -p 8083:8083 -v /data/nextcloud/app/data/setevoy/files/Books/CALIBRE/:/books technosoft2000/calibre-web
```

Check if `metadata.db` is present:

```
$ docker exec -ti books ls -l /books/metadata.db
-rw-r--r-- 1 xfs xfs 752640 Dec 13 07:51 /books/metadata.db
```

Open your URL in a browser, and set a path to the `/books` directory which has to contain the `metadata.db` file used by Calibre to store information about all books in the library:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217_091732.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217_091732.png)

Log in with the default _admin:admin123_:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_105453.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_105453.png)

And you’ll see your library now:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_105541.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_105541.png)

The _Categories_ menu here are just Tags from the Calibre:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_105653.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_105653.png)

And as in the common Calibre – you can view, add, edit and read books from the browser:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_110808.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_110808.png)

A browser’s reader:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_110839.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_110839.png)

#### _“Failed to create path /books/ (Permission denied)”_ error

If you’ll try to upload a file now you can face the following error:

> Failed to create path /books/Mark Menson/Tonkoe iskusstvo pofigizma_ Paradoksal’nyi sposob zhit’ schastlivo (Permission denied).

For me, it was an expected error as the directory `/data/nextcloud/app/data/setevoy/files/Books/CALIBRE/` is used now by both Nextcloud **and** Calibre Web Docker containers.

Check the user in the Calibre container:

```
$ docker exec -ti books ps | grep cali
68 calibre   0:08 /usr/bin/python /calibre-web/app/cps.py
```

And his UID:

```
$ docker exec -ti books id calibre
uid=15000(calibre) gid=15000(calibre) groups=15000(calibre),15000(calibre)
```

While the local directory on the host is owned by the:

```
$ ls -l /data/nextcloud/app/data/setevoy/files/Books/
total 4
drwxr-xr-x 117 www-data www-data 4096 Dec 16 09:32 CALIBRE
```

And the `www-data` user’s UID:

```
$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)
```

I.e. Calibre uses the `calibre` user with UID _15000_, but NGINX on the host and the Nextcloud container both are using `www-data` user with UID _33_.

To solve this issue – on the host create a new user _calibre_ with UID 15000:

```
$ sudo useradd -u 15000 calibre
$ id calibre
uid=15000(calibre) gid=15000(calibre) groups=15000(calibre)
```

Change the directory ownership:

```
$ sudo chown -R calibre:calibre /data/nextcloud/app/data/setevoy/files/Books/CALIBRE/
```

Restart Calibre:

```
$ docker restart calibre-web
calibre-web
```

Check upload now – must work now:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_121644.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216_121644.png)

#### Nextcloud `PUT` 403

But now Nexcloud is broken – on a desktop client I got 403 errors during sync, for example:

> 172.29.0.2 – setevoy [16/Dec/2019:13:22:24 +0000] “PUT /remote.php/dav/files/setevoy/Books/CALIBRE/Pol’%20Diubua/MySQL%20(68)/cover.jpg HTTP/1.1” 403 759 “-” “Mozilla/5.0 (Linux) mirall/2.6.1git (Nextcloud)”

To solve this issue – add newly added the _calibre_ user created above to the _www-data_ group:

```
$ usermod -a -G www-data calibre
```

Check his groups now:

```
$ id calibre
uid=15000(calibre) gid=15000(calibre) groups=15000(calibre),33(www-data)
```

Recursively change ownership – give full permissions to the `www-data` group members, e,g, for the `www-data` and the  `calibre` users:

```
$ find /data/nextcloud/app/data/setevoy/files/Books/CALIBRE/ -type d -exec chmod g+rwx {} +
```

And change the owner:

```
$ chown -R calibre:www-data /data/nextcloud/app/data/setevoy/files/Books/CALIBRE/
```

This is done, sync is working now as well.

#### Docker Compose

To have data persistence first let’s find where are data stored in the container, e.g. the application’s database with all its settings.

You can read the [documentation](https://github.com/janeczku/calibre-web/wiki/Configuration) (the recommended way!), or connect to the container:

```
$ docker exec -ti calibre-web bash
Find all _*.db_ files:
bash-4.4# find / -name "*.db"
/calibre-web/app/app.db
/calibre-web/app/gdrive.db
...
```

On the host create directories for the Docker Compose file and for the application’s data:

```
$ mkdir /opt/calibre-web/
$ mkdir -p /data/calibre/app
$ chown -R calibre:calibre /data/calibre/
```

In the `/opt/calibre-web/` directory create a `calibre-compose.yml` file:

```
version: '3'
services:
  calibre-web:
    user: "root:root"
    image: technosoft2000/calibre-web
    container_name: calibre-web
    ports:
      - 8083:8083
    volumes:
      - /data/nextcloud/app/data/setevoy/files/Books/CALIBRE/:/books
      -  /data/calibre/app:/calibre-web/app/ 
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: unless-stopped
```

Start the service:

```
$ docker-compose -f calibre-compose.yml up -d
```

A unit-file creation is described in the [Linux: systemd сервис для Docker Compose](https://rtfm.co.ua/linux-systemd-servis-dlya-docker-compose/), in this case, I’d added a `/etc/systemd/system/calibre.service` file:

```
[Unit]
Description=Calibre library service
Requires=docker.service
After=docker.service

[Service]
Restart=always
WorkingDirectory=/opt/calibre-web
ExecStart=/usr/local/bin/docker-compose -f calibre-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f calibre-compose.yml down

[Install]
WantedBy=multi-user.target
```

#### Calibre Web themes

Out from the box Calibre Web has two themes – the light one, default:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217_092123.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217_092123.png)

And the dark one:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217_092213.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217_092213.png)

### Pitfalls – merging the `metadata.db` with Nextcloud

This is issue relates to this current setup with the Nextcloud as storage, as it’s running on my own server and sometimes can be offline which can cause data un-sync on desktops.

The problem is, that the main Calibre’s file – the **metadata.db** – will be updated on the host’s filesystem when you’ll edit a book from the browser using Calibre Web, but this change will NOT trigger local Nextcloud instance to push this change to its clients when it’ll become back online as it’s running just like a server – it’s not client part.

Then, if your Calibre Desktop is configured to use the same Nextcloud and has a desktop client like [`nextcloud-desktop`](https://aur.archlinux.org/packages/nextcloud-desktop-git/), if you’ll run a local Calibre Desktop and will make any changes to its library – this will affect your `metadata.db` file and this will trigger your Nextcloud client to push these changes to the Nextcloud server, which will overwrite changes on the server.

So, to avoid it, need to manually synchronize your desktop’s Caliber’s directory content with the Nextcloud server before using it.

To do so, just issue the following command:

```
$ nextcloudcmd --user setevoy -p PASSWORD /home/setevoy/Nextcloud/Books/CALIBRE/ https://cloud.example.org.ua/Books/CALIBRE
```

This will grab all the changes from the _https://cloud.example.org.ua/Books/CALIBRE_ (i.e. `/data/nextcloud/app/data/setevoy/files/Books/CALIBRE/` on the Nextcloud’s host) to the local `/home/setevoy/Nextcloud/Books/CALIBRE/` directory (which is used by the desktop Calibre application).

### Moon+ Reader

The Moon+ Reader application is from my recent findings.

Can synchronize reading positions in books when using G DriveDropbox/WebDAV, sync comments, notes, bookmarks, etc.

Install it on your phone, add a WebDAV catalog:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216-111650.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216-111650.png)

And you have access to your Calibre’s library now:

#### [![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216-111535.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191216-111535.png)Synchronization settings

To make sync works in the Moon+ – open a book, then three dots in the top right corner > _Miscellaneous_, scroll bottom and enable the _Sync reading positions_:

[![](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217-110437.png "Calibre: домашняя онлайн-библиотека в браузере и Moon+ Reader")](https://rtfm.co.ua/wp-content/uploads/2019/12/Screenshot_20191217-110437.png)

Done.

### Similar posts

- <small>02/27/2017</small> [Docker: Compose down – network jmadmin_default has active endpoints](https://rtfm.co.ua/docker-compose-down-network-jmadmin_default-has-active-endpoints/)
- <small>09/26/2019</small> [Jenkins: Docker Compose deployment from Ansible with ECR authentication](https://rtfm.co.ua/en/jenkins-docker-compose-deployment-from-ansible-with-ecr-authentication/)
- <small>02/15/2019</small> [Docker: RabbitMQ: exec(): Unable to fork, Prometheus node_exporter и Docker limits](https://rtfm.co.ua/docker-rabbitmq-exec-unable-to-fork-prometheus-node_exporter-i-docker-limits/
- <small>08/14/2018</small> [Linux: systemd сервис для Docker Compose](https://rtfm.co.ua/linux-systemd-servis-dlya-docker-compose/)