Anki/docs/syncserver
Omar Kohl b189820218
Ensure data is stored in a volume in anki-sync-server Docker image (#3674)
Otherwise data would be lost by default when removing (or re-creating) a
container.

It would be possible to expose the default directory (e.g.
/home/anki/.syncserver) but it would be different for the two Dockerfiles and
less convenient for users of the Docker container to specify such a long path
when naming their volumes.

Setting the permissions is necessary since anki will be running with 'anki'
user permissions inside the container.
2025-01-10 21:42:55 +11:00
..
Dockerfile Ensure data is stored in a volume in anki-sync-server Docker image (#3674) 2025-01-10 21:42:55 +11:00
Dockerfile.distroless Ensure data is stored in a volume in anki-sync-server Docker image (#3674) 2025-01-10 21:42:55 +11:00
README.md Ensure data is stored in a volume in anki-sync-server Docker image (#3674) 2025-01-10 21:42:55 +11:00

Building and running Anki sync server in Docker

This is an example Dockerfile contributed by an Anki user, which shows how you can run a self-hosted sync server, similar to what AnkiWeb.net offers.

Building and running the sync server within a container has the advantage of fully isolating the build products and runtime dependencies from the rest of your system.

Requirements

Aspect Dockerfile Dockerfile.distroless
Shell & Tools Includes shell and tools Minimal, no shell or tools
Debugging Easier debugging with shell and tools Harder to debug due to minimal environment
Health Checks Supports complex health checks Health checks need to be simple or directly executable
Image Size Larger image size Smaller image size
Customization Easier to customize with additional packages Limited customization options
Attack Surface Larger attack surface due to more installed packages Reduced attack surface
Libraries More libraries available Limited libraries
Start-up Time Slower start-up time due to larger image size Faster start-up time
Tool Compatibility Compatible with more tools and libraries Compatibility limitations with certain tools
Maintenance Higher maintenance due to larger image and dependencies Lower maintenance with minimal base image

Building image

To proceed with building, you must specify the Anki version you want, by replacing <version> with something like 24.11 and <Dockerfile> with the chosen Dockerfile (e.g., Dockerfile or Dockerfile.distroless)

# Execute this command from the root directory of your project
docker build -f docs/syncserver/<Dockerfile> --no-cache --build-arg ANKI_VERSION=<version> -t anki-sync-server .

Run container

Once done with build, you can proceed with running this image with the following command:

# this will create anki server
docker run -d \
    -e "SYNC_USER1=admin:admin" \
    -p 8080:8080 \
    --mount type=volume,src=anki-sync-server-data,dst=/anki_data \
    --name anki-sync-server \
    anki-sync-server

However, if you want to have multiple users, you have to use the following approach:

# this will create anki server with multiple users
docker run -d \
    -e "SYNC_USER1=admin:admin" \
    -e "SYNC_USER2=admin2:admin2" \
    -p 8080:8080 \
    --mount type=volume,src=anki-sync-server-data,dst=/anki_data \
    --name anki-sync-server \
    anki-sync-server

Moreover, you can pass additional env vars mentioned here. Note that you should not override SYNC_BASE because you risk data loss.