Containerize Calibre To Serve Up Your Books Using Podman.


That’s a mouthful. Anyway, I got bored last night and since I haven’t messed with Docker and such I decided what the hell. Well, Docker looked like it wanted my to create an account and maybe buy things later so I decided to play with Podman instead. Took me about an hour to figure it all out. I found Podman Desktop and that helped with the fumbling. That was last night before bed…

Today at work a friend mentioned using Docker to serve up his books in Calibre. Sounded neat. I created an image and ran it. Worked great. Then I decided to script it so it creates a new Calibre library with books, creates the container, and copies the library over and fires it up so I can grab said books with a web browser. Luckily Calibre has command line ability!

The script creates a folder and saves the Dockerfile and creates a books folder. It then creates a Calibre library in the new books folder and adds books from a location you provide. I did not make that a runtime input so you will need to change it in the script. It then creates the container, installs Calibre, and copies the books over. It then runs the container. If you want an easy way to manage the image and run the container, get a copy of Podman Desktop. Once the script runs the image and container it created will display there, or mange it in the terminal.

Save this script as and run it in the terminal with: sh

You can also manually run the commands from this script if you prefer a more hands on deal. Also, if you are running this on anything other than Ubuntu/Debian derivatives you may want to change the apt commands to whatever your system uses, i.e., dnf, pacman, etc. between lines 47 to 56. You can install Podman manually and remove that section altogether if you prefer. Do not remove the dnf install for Calibre as that is running in the container and you need that.

Hope it’s useful in one way or another. Enjoy!

#!/usr/bin/env bash

# A quick little script to create and serve up a calibre library in a container.
# Created by C. Nichols,
# Jan. 31, 2023
# Be sure to change the paths to your books so they can be added to the library.
# If the $USER var doesn't contain your user name try whoami or manually set it.

MY_BOOKS_PTH="/home/$USER/Books" # Path to the books you want added to Calibre.

# Create the base where we set our container creation specifics.

# Create our library and add our books. This gets copied to the container.
calibredb --library-path=$TMP_CALIBRE_PTH add $MY_BOOKS_PTH -r

echo 'Done setting up Calibre.'

# Write our Dockerfile that will create the container and copy our books.
cat <<EOF | tee $DOCKER_FILE

RUN dnf install -y calibre && dnf clean all

RUN mkdir -p /opt/books
ADD ./books /opt/books

WORKDIR  /opt/books
VOLUME ["/opt/books"] # For access to...


# http://localhost:8080
ENTRYPOINT ["calibre-server", "/opt/books"]

echo 'Done writing Dockerfile.'

# Install podman if it is not installed.
dpkg -l "podman"
if [ $? = '0' ]
    printf "Podman is installed."
elif [ $? = '1' ]
    printf "Installing Podman..."
    sudo apt update && install podman

echo 'Creating image and running container.'

# Create the image and run it. Test by visiting http://localhost:8080
podman build -t "calibre:latest" .

echo "Starting the container now!"
echo "Ctrl+z should exit this script. To stop the container: "
echo " podman stop calibre-server"
echo "I would recommend grabbing podman desktop then you can easily manage and run the container in a GUI."
echo "To start the container next time from the terminal, all you need to do is run: "
echo " podman run --name "calibre-server" -p 8080:8080 localhost/calibre"
echo "You can delete the contents of $TMP_DOCKER_PTH and this script once the container has been created."
echo "now go visit: http://localhost:8080"

podman run --name "calibre-server" -p 8080:8080 localhost/calibre