# Calibre Docker Container with Docker Compose This repository contains a Dockerfile, Docker Compose configuration, and associated scripts to set up a Calibre environment within a Docker container. The container is based on the official Ubuntu image and includes Calibre, cron for scheduling tasks, and an entrypoint script to handle timezone configuration and cron service startup. The Docker Compose file simplifies the deployment process by allowing you to configure environment variables, volumes, and ports in a single file. --- ## Features - **Calibre Installation**: The container installs Calibre, a powerful and easy-to-use e-book manager. - **Cron Jobs**: Supports custom cron jobs for automated tasks, such as running scripts at specified intervals. - **Timezone Configuration**: Allows setting the timezone via the `TZ` environment variable. - **Logging**: Optional logging for cron jobs to facilitate debugging. - **Docker Compose Support**: Easily manage container configuration, volumes, and ports using `docker-compose.yml`. --- ## Getting Started ### Prerequisites - Docker installed on your machine. - Docker Compose installed (if not, follow the [official guide](https://docs.docker.com/compose/install/)). --- ### Docker Compose Configuration The `docker-compose.yml` file simplifies the deployment process. Below is the configuration: ```yaml services: calibre-cron: image: calibre-cron:0.9 container_name: ${CALIBRE_NAME} environment: - PUID=1000 - PGID=1000 - TZ=Asia/Hong_Kong volumes: - ${CALIBRE_CRON}:/etc/cron.d - ${CALIBRE_RECIPE}:/calibre/recipe - ${NEWS_PATH}:/news ports: - 8780:8080 - 8781:8081 restart: "no" ``` #### Environment Variables - `CALIBRE_NAME`: The name of the container. - `PUID`: User ID for file permissions (default: `1000`). - `PGID`: Group ID for file permissions (default: `1000`). - `TZ`: Timezone (default: `Asia/Hong_Kong`). - `CALIBRE_CRON`: Path to the host directory for custom cron jobs. - `CALIBRE_RECIPE`: Path to the host directory for Calibre recipes. - `NEWS_PATH`: Path to the host directory for news files. #### Ports - `8780:8080`: Maps host port 8780 to container port 8080. - `8781:8081`: Maps host port 8781 to container port 8081. #### Volumes - `${CALIBRE_CRON}:/etc/cron.d`: Mounts the host directory for custom cron jobs. - `${CALIBRE_RECIPE}:/calibre/recipe`: Mounts the host directory for Calibre recipes. - `${NEWS_PATH}:/news`: Mounts the host directory for news files. --- ### Building the Docker Image To build the Docker image, navigate to the directory containing the Dockerfile and run: ```bash docker build -t calibre-cron:0.9 . ``` --- ### Running with Docker Compose 1. Create a `.env` file in the same directory as `docker-compose.yml` and define the required environment variables: ```bash CALIBRE_NAME=my-calibre-container CALIBRE_CRON=/path/to/cron/jobs CALIBRE_RECIPE=/path/to/calibre/recipes NEWS_PATH=/path/to/news/files ``` 2. Start the container using Docker Compose: ```bash docker-compose up -d ``` --- ### Custom Cron Jobs You can add custom cron jobs by placing them in the `${CALIBRE_CRON}` directory on your host machine. The provided `calibre-cron` file is an example of a cron job that runs a script at 5 AM daily: ```bash 0 5 * * * /calibre/recipe/upkindle.sh >> /var/log/upkindle.log 2>&1 ``` --- ### Entrypoint Script The `entrypoint.sh` script handles timezone configuration and starts the cron service. It checks for the `TZ` environment variable and sets the timezone accordingly. --- ## Directory Structure - `/calibre/library`: Directory for storing Calibre library files. - `/etc/cron.d`: Directory for custom cron jobs. - `/var/log/calibre-cron.log`: Log file for cron job output (optional). - `/calibre/recipe`: Directory for Calibre recipes. - `/news`: Directory for news files. --- ## Example Cron Job The `calibre-cron` file contains an example cron job that runs a script at 5 AM daily: ```bash 0 5 * * * /calibre/recipe/upkindle.sh >> /var/log/upkindle.log 2>&1 ``` --- ## Logging Cron job output can be logged to `/var/log/calibre-cron.log` for debugging purposes. Ensure your cron jobs redirect their output to this file or another log file as needed. --- ## License This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. --- ## Acknowledgments - [Calibre](https://calibre-ebook.com/) for providing an excellent e-book management tool. - [Docker](https://www.docker.com/) for simplifying containerization. - [Docker Compose](https://docs.docker.com/compose/) for streamlining multi-container setups. --- ## Contributing Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes. --- ## Support For support, please open an issue in the repository or contact the maintainer directly. --- This README provides a comprehensive guide to setting up and running the Calibre Docker container with Docker Compose. For more detailed instructions, refer to the Dockerfile, `docker-compose.yml`, and associated scripts.