Add docker migration guide
[akkoma] / docs / docs / installation / docker_en.md
1 # Installing in Docker
2
3 ## Installation
4
5 This guide will show you how to get akkoma working in a docker container,
6 if you want isolation, or if you run a distribution not supported by the OTP
7 releases.
8
9 If you want to migrate from or OTP to docker, check out [the migration guide](./migrating_to_docker_en.md).
10
11 ### Prepare the system
12
13 * Install docker and docker-compose
14 * [Docker](https://docs.docker.com/engine/install/)
15 * [Docker-compose](https://docs.docker.com/compose/install/)
16 * This will usually just be a repository installation and a package manager invocation.
17 * Clone the akkoma repository
18 * `git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable`
19 * `cd akkoma`
20
21 ### Set up basic configuration
22
23 ```bash
24 cp docker-resources/env.example .env
25 echo "DOCKER_USER=$(id -u):$(id -g)" >> .env
26 ```
27
28 This probably won't need to be changed, it's only there to set basic environment
29 variables for the docker-compose file.
30
31 ### Building the container
32
33 The container provided is a thin wrapper around akkoma's dependencies,
34 it does not contain the code itself. This is to allow for easy updates
35 and debugging if required.
36
37 ```bash
38 ./docker-resources/build.sh
39 ```
40
41 This will generate a container called `akkoma` which we can use
42 in our compose environment.
43
44 ### Generating your instance
45
46 ```bash
47 mkdir pgdata
48 ./docker-resources/manage.sh mix deps.get
49 ./docker-resources/manage.sh mix compile
50 ./docker-resources/manage.sh mix pleroma.instance gen
51 ```
52
53 This will ask you a few questions - the defaults are fine for most things,
54 the database hostname is `db`, and you will want to set the ip to `0.0.0.0`.
55
56 Now we'll want to copy over the config it just created
57
58 ```bash
59 cp config/generated_config.exs config/prod.secret.exs
60 ```
61
62 ### Setting up the database
63
64 We need to run a few commands on the database container, this isn't too bad
65
66 ```bash
67 docker-compose run --rm --user akkoma -d db
68 # Note down the name it gives here, it will be something like akkoma_db_run
69 docker-compose run --rm akkoma psql -h db -U akkoma -f config/setup_db.psql
70 docker stop akkoma_db_run # Replace with the name you noted down
71 ```
72
73 Now we can actually run our migrations
74
75 ```bash
76 ./docker-resources/manage.sh mix ecto.migrate
77 # this will recompile your files at the same time, since we changed the config
78 ```
79
80 ### Start the server
81
82 We're going to run it in the foreground on the first run, just to make sure
83 everything start up.
84
85 ```bash
86 docker-compose up
87 ```
88
89 If everything went well, you should be able to access your instance at http://localhost:4000
90
91 You can `ctrl-c` out of the docker-compose now to shutdown the server.
92
93 ### Running in the background
94
95 ```bash
96 docker-compose up -d
97 ```
98
99 ### Create your first user
100
101 If your instance is up and running, you can create your first user with administrative rights with the following task:
102
103 ```shell
104 ./docker-resources/manage.sh mix pleroma.user new MY_USERNAME MY_EMAIL@SOMEWHERE --admin
105 ```
106
107 And follow the prompts
108
109 ### Reverse proxies
110
111 This is a tad more complex in docker than on the host itself. It
112
113 You've got two options.
114
115 #### Running caddy in a container
116
117 This is by far the easiest option. It'll handle HTTPS and all that for you.
118
119 ```bash
120 mkdir caddy-data
121 mkdir caddy-config
122 cp docker-resources/Caddyfile.example docker-resources/Caddyfile
123 ```
124
125 Then edit the TLD in your caddyfile to the domain you're serving on.
126
127 Uncomment the `caddy` section in the docker-compose file,
128 then run `docker-compose up -d` again.
129
130 #### Running a reverse proxy on the host
131
132 If you want, you can also run the reverse proxy on the host. This is a bit more complex, but it's also more flexible.
133
134 Follow the guides for source install for your distribution of choice, or adapt
135 as needed. Your standard setup can be found in the [Debian Guide](../debian_based_en/#nginx)
136
137 ### You're done!
138
139 All that's left is to set up your frontends.
140
141 The standard from-source commands will apply to you, just make sure you
142 prefix them with `./docker-resources/manage.sh`!
143
144 {! installation/frontends.include !}
145
146 ### Updating Docker Installs
147
148 ```bash
149 git pull
150 ./docker-resources/build.sh
151 ./docker-resources/manage.sh mix deps.get
152 ./docker-resources/manage.sh mix compile
153 ./docker-resources/manage.sh mix ecto.migrate
154 docker-compose restart akkoma db
155 ```
156
157 #### Further reading
158
159 {! installation/further_reading.include !}
160
161 {! support.include !}