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