A Docker container that packages the Anki Linux client with AnkiConnect plugin to provide headless Anki functionality accessible via HTTP API.
- Headless Operation: Runs Anki without GUI using virtual display (Xvfb)
- AnkiConnect Integration: Full API access via HTTP on port 8765
- Data Persistence: Volume mounting for Anki collections and media
- Security: Runs as non-root user with minimal privileges
- Health Checks: Built-in health monitoring
- CORS Support: Configurable cross-origin resource sharing
- Clone or download the project files
- Build and start the container:
docker-compose up -d- Test the AnkiConnect API:
curl -X POST http://localhost:8765 \
-H "Content-Type: application/json" \
-d '{"action": "version", "version": 6}'# Build the image
docker build -t anki-headless .
# Run the container
docker run -d \
--name anki-headless \
-p 8765:8765 \
-v anki_data:/home/anki/.local/share/Anki2 \
anki-headless| Variable | Default | Description |
|---|---|---|
ANKI_DATA_DIR |
/home/anki/.local/share/Anki2 |
Anki data directory |
ANKI_PORT |
8765 |
AnkiConnect port |
ANKI_CORS_ORIGINS |
* |
CORS allowed origins |
/home/anki/.local/share/Anki2- Main Anki data directory/home/anki/.local/share/Anki2/User 1/collection.media- Media files
curl -X POST http://localhost:8765 \
-H "Content-Type: application/json" \
-d '{"action": "version", "version": 6}'curl -X POST http://localhost:8765 \
-H "Content-Type: application/json" \
-d '{
"action": "addNote",
"version": 6,
"params": {
"note": {
"deckName": "Default",
"modelName": "Basic",
"fields": {
"Front": "What is Docker?",
"Back": "A containerization platform"
}
}
}
}'curl -X POST http://localhost:8765 \
-H "Content-Type: application/json" \
-d '{"action": "deckNames", "version": 6}'curl -X POST http://localhost:8765 \
-H "Content-Type: application/json" \
-d '{
"action": "importPackage",
"version": 6,
"params": {
"path": "/path/to/deck.apkg"
}
}'docker build \
--build-arg ANKI_VERSION=25.07.5 \
--build-arg ANKICONNECT_VERSION=23.10.29.0 \
-t anki-headless:custom .Use the alternative docker-compose configuration for development:
# Create local directories
mkdir -p anki-data anki-media
# Use development configuration
docker-compose -f docker-compose.yml up -d# View container logs
docker-compose logs -f anki-headless
# Access container shell
docker-compose exec anki-headless bash
# Check AnkiConnect status
docker-compose exec anki-headless curl http://localhost:8765├── Dockerfile # Multi-stage Docker build
├── docker-compose.yml # Docker Compose configuration
├── start-anki.sh # Container startup script
├── config.json # AnkiConnect configuration
├── meta.json # AnkiConnect metadata
└── README.md # This file
- Check logs:
docker-compose logs anki-headless - Verify port availability:
netstat -tuln | grep 8765 - Check disk space for volumes
- Verify container health:
docker-compose ps - Test network connectivity:
docker-compose exec anki-headless curl localhost:8765 - Check AnkiConnect configuration in volume
- Ensure proper file permissions on mounted volumes
- Check available disk space
- Verify file paths are accessible within container
- Increase memory limit in docker-compose.yml
- Monitor memory usage:
docker stats anki-headless - Consider using swap if needed
- Container runs as non-root user (
anki) - Minimal system capabilities
- No new privileges allowed
- CORS configured for development (adjust for production)
- Consider adding authentication for production use
- Memory: Default limit is 512MB, adjust based on collection size
- CPU: CPU shares set to 1024, modify for multi-container environments
- Storage: Use fast storage for better database performance
- Network: Use host networking for maximum performance if security allows
server {
listen 80;
server_name anki.example.com;
location / {
proxy_pass http://localhost:8765;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}version: '3.8'
services:
anki-headless:
image: anki-headless:latest
deploy:
replicas: 1
resources:
limits:
memory: 512M
reservations:
memory: 256M
ports:
- "8765:8765"
volumes:
- anki_data:/home/anki/.local/share/Anki2- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is provided as-is for educational and development purposes. Please respect Anki and AnkiConnect licensing terms.
- Anki - The fantastic spaced repetition software
- AnkiConnect - The plugin that makes API access possible
- Community contributors and testers