XLS-to-CSV converter in custom-build Docker container

Dockerfile – to create custom docker container
docker-compose.yml – to build/start container
converter.py – python script to convert exel files
entrypoint.sh – to start cron service in container
crontab.txt – to schedule cron task to run every 5 min

Dockerfile content:

FROM python:3.11-slim

# Install cron
RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/*

# Install Python deps
RUN pip install --no-cache-dir pandas xlrd openpyxl

# Create directories
RUN mkdir -p /app/source /app/destination

WORKDIR /app

# Copy files
COPY converter.py entrypoint.sh crontab.txt /app/

# Make entrypoint executable
RUN chmod +x /app/entrypoint.sh

# Setup cron
RUN crontab /app/crontab.txt

CMD ["/app/entrypoint.sh"]

docker-compose.yml content:

services:
  excel-converter:
    build:
      context: .
#      proxy for Docker if needed
#      args:
#        http_proxy: http://proxy:3128
#        https_proxy: http://proxy:3128
#        no_proxy: localhost,127.0.0.1
    container_name: excel-converter
    volumes:
      - /opt/data/source:/app/source
      - /opt/data/destination:/app/destination
    restart: unless-stopped

content of converter.py

import pandas as pd
from pathlib import Path

SOURCE_DIR = Path("/app/source")
DEST_DIR = Path("/app/destination")

def convert_files():
    for file in SOURCE_DIR.glob("*.xls*"):  # matches .xls and .xlsx
        try:
            print(f"Processing {file}")
            df = pd.read_excel(file)
            out_file = DEST_DIR / (file.stem + ".csv")
            df.to_csv(out_file, index=False, encoding="utf-8")
            file.unlink()  # delete original
            print(f"Converted {file} → {out_file}")
        except Exception as e:
            print(f"Failed to convert {file}: {e}")

if __name__ == "__main__":
    convert_files()

content of entrypoint.sh

#!/bin/bash
# Start cron in foreground
cron -f

content of crontab.txt

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
*/5 * * * * python3 /app/converter.py >> /var/log/cron.log 2>&1

build and start converter

docker compose up -d --force-recreate

enjoy results.