Skip to content

Commit b189820

Browse files
authored
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.
1 parent 9460911 commit b189820

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

docs/syncserver/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ARG SYNC_PORT=8080
1515

1616
RUN adduser -D -h /home/anki anki
1717

18+
RUN mkdir -p /anki_data && chown -R anki /anki_data
19+
1820
COPY --from=builder /anki-server/bin/anki-sync-server /usr/local/bin/anki-sync-server
1921

2022

@@ -24,6 +26,8 @@ USER anki
2426

2527
ENV SYNC_PORT=${SYNC_PORT}
2628

29+
ENV SYNC_BASE=/anki_data
30+
2731
EXPOSE ${SYNC_PORT}
2832

2933
CMD ["anki-sync-server"]
@@ -33,4 +37,6 @@ CMD ["anki-sync-server"]
3337
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
3438
CMD wget -qO- http://127.0.0.1:${SYNC_PORT}/health || exit 1
3539

40+
VOLUME /anki_data
41+
3642
LABEL maintainer="Jean Khawand <[email protected]>"

docs/syncserver/Dockerfile.distroless

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ COPY --from=builder /anki-server/bin/anki-sync-server /usr/bin/anki-sync-server
1717

1818
ENV SYNC_PORT=${SYNC_PORT}
1919

20+
ENV SYNC_BASE=/anki_data
21+
2022
EXPOSE ${SYNC_PORT}
2123

2224
CMD ["anki-sync-server"]
@@ -26,4 +28,6 @@ CMD ["anki-sync-server"]
2628
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
2729
CMD ["anki-sync-server", "--healthcheck"]
2830

31+
VOLUME /anki_data
32+
2933
LABEL maintainer="Jean Khawand <[email protected]>"

docs/syncserver/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,27 @@ Once done with build, you can proceed with running this image with the following
3838

3939
```bash
4040
# this will create anki server
41-
docker run -d -e "SYNC_USER1=admin:admin" -p 8080:8080 --name anki-sync-server anki-sync-server
41+
docker run -d \
42+
-e "SYNC_USER1=admin:admin" \
43+
-p 8080:8080 \
44+
--mount type=volume,src=anki-sync-server-data,dst=/anki_data \
45+
--name anki-sync-server \
46+
anki-sync-server
4247
```
4348

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

4651
```bash
4752
# this will create anki server with multiple users
48-
docker run -d -e "SYNC_USER1=test:test" -e "SYNC_USER2=test2:test2" -p 8080:8080 --name anki-sync-server anki-sync-server
53+
docker run -d \
54+
-e "SYNC_USER1=admin:admin" \
55+
-e "SYNC_USER2=admin2:admin2" \
56+
-p 8080:8080 \
57+
--mount type=volume,src=anki-sync-server-data,dst=/anki_data \
58+
--name anki-sync-server \
59+
anki-sync-server
4960
```
5061

51-
Moreover, you can pass additional env vars mentioned [here](https://docs.ankiweb.net/sync-server.html)
62+
Moreover, you can pass additional env vars mentioned
63+
[here](https://docs.ankiweb.net/sync-server.html). Note that you should **not**
64+
override SYNC_BASE because you risk data loss.

0 commit comments

Comments
 (0)