This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is docker-crontab, a Docker-based cron job scheduler that allows running complex cron jobs in other containers. It's a lightweight alternative to mcuadros/ofelia with enterprise features.
-
Dockerfile: Single-stage build using Docker-in-Docker Alpine base
- Based on
docker:dind-alpinewith cron and Docker client - Uses
su-execfor proper user privilege handling - Configurable Docker group ID via
DOCKER_GIDbuild arg (default: 999)
- Based on
-
entrypoint.sh: Main orchestration script that:
- Normalizes config files (JSON/YAML/TOML) using
yqandjq - Processes shared settings via
~~shared-settingskey - Generates crontab entries and executable scripts
- Installs crontab files in user-writable directory (
/opt/crontab/crontabs) - Supports both
image(docker run) andcontainer(docker exec) execution modes - Handles trigger chains and onstart commands
- Drops privileges to
dockeruser for security
- Normalizes config files (JSON/YAML/TOML) using
- Supports JSON, YAML, and TOML config formats
- Config can be array or mapping (top-level keys ignored for organization)
- Special
~~shared-settingskey for shared configuration - Key fields:
schedule,command,image/container,dockerargs,trigger,onstart - Schedule supports standard crontab syntax plus shortcuts (@hourly, @daily/@midnight, @weekly, @monthly, @yearly/@annually, @random)
- Additional fields:
comment,name,environment,expose,networks,ports,volumes
- Config normalization: All formats converted to working JSON
- Script generation: Each job becomes executable shell script in
/opt/crontab/jobs/ - Crontab creation: Standard crontab file generated with proper scheduling
- Trigger processing: Post-job triggers executed in sequence
- Onstart handling: Jobs marked with
onstart: truerun immediately
# Basic build
docker build -t crontab .
# Build with custom Docker group ID
docker build --build-arg DOCKER_GID=$(stat -c '%g' /var/run/docker.sock) -t crontab .# Command line execution
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v ./config-samples/config.sample.json:/opt/crontab/config.json:ro \
-v ./logs:/var/log/crontab:rw \
crontab
# With host directory for persistent config/logs
# Container will create directories with proper permissions
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v $PWD/crontab-config:/opt/crontab:rw \
-v $PWD/crontab-logs:/var/log/crontab:rw \
crontab
# Docker Compose
docker-compose up# Test with sample configuration
docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v ./config-samples/config.sample.json:/opt/crontab/config.json:ro \
crontab
# Debug mode - view generated crontab and scripts
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v ./config-samples/config.sample.json:/opt/crontab/config.json:ro \
-e TEST_MODE=1 \
crontab bash -c "cat /tmp/crontab-docker-testing/test && ls -la /tmp/crontab-docker-testing/jobs/"The repository includes sample configurations in config-samples/ for testing different scenarios.
- Docker Socket Access: Container requires read-only access to
/var/run/docker.sock - User Permissions: Uses
dockeruser with configurable GID to match host Docker group - Volume Mounts: Config and log directories should be mounted as volumes
- Network Access: For docker-compose usage, containers need network connectivity via
--networkindockerargs
-
"failed switching to 'docker': operation not permitted": Docker group GID mismatch
- Solution: Rebuild with correct GID using
--build-arg DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
- Solution: Rebuild with correct GID using
-
"Permission denied" creating directories: Volume mount permissions issue
- Solution: Ensure host directories have correct ownership before mounting
- Quick fix:
sudo chown -R $(id -u):$(id -g) /path/to/host/directory - Or let container create directories (it runs as root initially, then drops privileges to
dockeruser)
-
Jobs not executing: Check crontab generation and script permissions
- Debug: Use
TEST_MODE=1environment variable to inspect generated files - Verify crontab file exists: Check
/opt/crontab/crontabs/dockerinside container - Check logs: Container outputs cron job execution to stdout/stderr
- Debug: Use
-
Container networking issues: Ensure proper network configuration in
dockerargs- For docker-compose: Add
--network <compose_network_name>to dockerargs
- For docker-compose: Add
- Generated scripts:
/opt/crontab/jobs/ - Working config:
/opt/crontab/config.working.json - Crontab directory:
/opt/crontab/crontabs/ - Crontab file:
/opt/crontab/crontabs/docker - Logs: Container stdout/stderr (configure external logging as needed)
- Container runs as non-root
dockeruser for security - Docker socket access is read-only to prevent container escape
- Uses
su-execfor privilege dropping instead ofsudo - Single-stage build minimizes attack surface
- SBOM and provenance generation enabled in CI/CD
GitHub Actions workflow (.github/workflows/build.yml):
- Builds on push to main and PRs
- Multi-platform support (linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6)
- Publishes to GitHub Container Registry (
ghcr.io) - Includes security scanning with SBOM and provenance
- Discord notifications for build status
- Weekly scheduled builds for base image security updates