mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00

PUID and PGID are optional env variables to specify the user and group id of the user that the anki-sync-server process should run with. This gives more flexibility for solving permission problems with volumes and is a common pattern for Docker images (e.g. see here: https://docs.linuxserver.io/general/understanding-puid-and-pgid/) The anki-sync-server process will write any files with the permissions of the user it's running with, which can be a problem when you need to access those files from outside the container or when they are being written into a bind mount that is owned by a particular user on the host system. To be able to implement this the entrypoint.sh needs to run as root (since it needs to create a user and change file permissions). anki-sync-server then needs to be started with the user 'anki', which is why the new dependency 'su-exec' is required. The user 'anki' and group 'anki-group' can no longer be created at image build time because then their ids would be fixed. Also update the build instructions to require building the Docker image inside the directory where the Dockerfile resides since the build now needs to copy the entrypoint.sh and it seems wrong the specify the path docs/syncserver/entrypoint.sh inside the Dockerfile.
75 lines
4.2 KiB
Markdown
75 lines
4.2 KiB
Markdown
# 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
|
|
|
|
- [x] [Docker](https://docs.docker.com/get-started/)
|
|
|
|
| **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 |
|
|
| **Custom uid/gid** | ✅ It's possible to pass in PUID and PGID | ❌ PUID and PGID are not supported |
|
|
|
|
# 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`)
|
|
|
|
```bash
|
|
# Execute this command from this directory
|
|
docker build -f <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:
|
|
|
|
```bash
|
|
# 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
|
|
```
|
|
|
|
If the image you are using was built with `Dockerfile` you can specify the
|
|
`PUID` and `PGID` env variables for the user and group id of the process that
|
|
will run the anki-sync-server process. This is valuable when you want the files
|
|
written and read from the `/anki_data` volume to belong to a particular
|
|
user/group e.g. to access it from the host or another container. Note the the
|
|
ids chosen for `PUID` and `PGID` must not already be in use inside the
|
|
container (1000 and above is fine). For example add `-e "PUID=1050"` and `-e
|
|
"PGID=1050"` to the above command.
|
|
|
|
If you want to have multiple Anki users that can sync their devices, you can
|
|
specify multiple `SYNC_USER` as follows:
|
|
|
|
```bash
|
|
# 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](https://docs.ankiweb.net/sync-server.html). Note that you should **not**
|
|
override SYNC_BASE because you risk data loss.
|