forked from
tangled.org/knot-docker
Community maintained Docker config for the knot server
1# Knot Docker
2
3> **IMPORTANT**
4> This is a community maintained repository, support is not guaranteed.
5
6Docker container and compose setup to run a [Tangled](https://tangled.org) knot
7and host your own repository data.
8
9## Pre-built Images
10
11There is a [repository](https://atcr.io/r/tangled.org/knot) of pre-built images
12for tags starting at `v1.13.0-alpha` if you prefer.
13
14```
15docker pull atcr.io/tangled.org/knot:latest
16```
17
18Note that these are *not* official images, you use them at your own risk.
19
20## Building The Image
21
22By default the `Dockerfile` will build the latest tag, but you can change it
23with the `TAG` build argument.
24
25```sh
26docker build -t knot:latest --build-arg TAG=master .
27```
28
29The command above for example will build the latest commit on the `master`
30branch.
31
32By default it will also create a `git` user with user and group ID 1000:1000,
33but you can change it with the `UID` and `GID` build arguments.
34
35```sh
36docker build -t knot:latest --build-arg UID=$(id -u) GID=$(id -g)
37```
38
39The command above for example will create a user with the host user's UID and GID.
40This is useful if you are bind mounting the repositories and app folder on the host,
41as in the provided `docker-compose.yml` file.
42
43<hr style="margin-bottom: 20px; margin-top: 10px" />
44
45When using compose, these can be specified as build arguments which will be
46passed to the builder.
47
48```yaml
49build:
50 context: .
51 args:
52 TAG: master
53 UID: 1000
54 GID: 1000
55```
56
57This will for example tell docker to build it using the `master` branch like
58the command.
59
60## Setting Up The Image
61
62The simplest way to set up your own knot is to use the provided compose file
63and run the following:
64
65First, create directories that will be used as docker volumes:
66
67```sh
68mkdir keys repositories server
69chown -R 1000:1000 keys repositories server
70```
71
72Replace the `1000:1000` ids if you built your docker image with different ids.
73
74Then start the knot container using:
75
76```sh
77export KNOT_SERVER_HOSTNAME=example.com
78export KNOT_SERVER_OWNER=did:plc:yourdidgoeshere
79export KNOT_SERVER_PORT=443
80docker compose up -d
81```
82
83If you also want to setup a reverse proxy with TLS termination, use the `caddy` profile of the in the compose file:
84
85```sh
86docker compose --profile caddy up -d
87```
88
89The knot server will then be exposed on the given port.
90
91## Pushing code using SSH
92
93When starting a knot in a docker container, the knot listens to a SSH port that is not the same as the host.
94The `docker-compose.yml` file uses port 2222 as an example:
95
96```yml
97services:
98 knot:
99 image: atcr.io/tangled.org/knot:latest
100 ports:
101 - "5555:5555"
102 - "2222:22"
103```
104
105By default, when you push code to a remote, such as `git@knot.example.com/someRepo`, Git will use port 22, which will resolve to your docker host's SSH daemon, not the container.
106
107To connect to the knot container over Git with SSH, configure your SSH client to use the port exposed by the container in `~/.ssh/config`.
108
109```
110Host knot.example.com
111 Port 2222
112```
113
114You can then test your configuration using `ssh -T git@knot.example.com`.