This project is inspired by pnorcross/anki-desktop-docker, with a few tweaks. It provides a Dockerfile that uses linuxserver/docker-baseimage-kasmvnc as the base image to run the desktop version of Anki inside a container.
Why? Because it makes automating Anki (with addons like AnkiConnect) easier.
The Anki desktop app runs in a browser (via VNC) on port 3000. Your Anki data is stored in a volume mounted at /config/app inside the container.
- Docker
- Docker Compose (usually bundled with newer Docker versions)
- Ubuntu (focus is on Linux, but Docker can work on Windows too with a slightly different setup)
- cron (for scheduling tasks)
- AnkiConnect addon (to enable scripting Anki via port
8765)
Builds the container with Anki 25.02.7 You can change the Anki version, but compatibility may vary.
Contains commands to install Docker on Ubuntu.
Helps clean up system resources. Anki seems to have a memory leak—on systems with only 1GB RAM, the container might become unresponsive after ~1 day. You can use cron to run cleanup every 12h.
Uses curl to call AnkiConnect (on port 8765) to create a backup. Schedule this with cron for daily backups.
Also uses curl to call AnkiConnect. It forces a sync and optionally reschedules cards (useful with FSRS + AnkiDroid combo).
Create a docker-compose.yml in the root of the repo:
services:
anki-desktop:
build:
context: ./
dockerfile: Dockerfile
environment:
- PUID=1000
- PGID=1000
volumes:
- ~/.local/share/Anki2:/config/app/Anki2
- ~/backups:/config/app/backups
ports:
- 3000:3000
# Anki Connect port
- 8765:8765
- The first volume maps your local Anki data (on Ubuntu it's usually at
~/.local/share/Anki2) into the container. - The second volume is for backups you extract via AnkiConnect.
To get started:
git clone <this-repo>
cd anki-desktop-docker
docker compose up --build -dThen open your browser and head to:
http://localhost:3000
Make sure your AnkiConnect config (inside Anki) looks like this:
{
"apiKey": null,
"apiLogPath": null,
"ignoreOriginList": [],
"webBindAddress": "0.0.0.0",
"webBindPort": 8765,
"webCorsOrigin": "http://localhost",
"webCorsOriginList": ["*"]
}Open your crontab:
crontab -eAnd add:
0 8 * * * (~/anki-desktop-docker/sync && date) >> ~/sync.log 2>&1
0 9 * * * (~/anki-desktop-docker/backup && date) >> ~/backup.log 2>&1
0 10,22 * * * (~/anki-desktop-docker/cleanup && date) >> ~/cleanup.log 2>&1This sets up:
- 8:00 UTC — Sync
- 9:00 UTC — Backup
- 10:00 & 22:00 UTC — Cleanup