|
| 1 | +# Running Cozy inside Docker |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Cozycloud publish the `cozy/cozy-stack` docker production image to run the |
| 6 | +`cozy-stack` inside a docker container. It comes with everything bundled and |
| 7 | +preconfigured: |
| 8 | + |
| 9 | +- `cozy-stack` backend server |
| 10 | +- asynchronous konnector and services execution |
| 11 | +- preconfigured PDF and SVG thumbnail generation |
| 12 | +- Mail relay |
| 13 | +- ... |
| 14 | + |
| 15 | +Cozycloud also publish a docker-compose onfiguration to automatically |
| 16 | +setup a whole Cozy hosting infrastructure inside docker for selfhosting |
| 17 | +purposes with a CouchDB database as well as a frontend reverse proxy with |
| 18 | +on-demand TLS (automatic TLS certificate issuance). |
| 19 | + |
| 20 | +This guide will help you selfhost your Cozy inside docker with docker-compose. |
| 21 | + |
| 22 | +## Requirements |
| 23 | + |
| 24 | +First you need a working docker installation with compose plugin. |
| 25 | + |
| 26 | +Plense refer to official [Docker installation guide](https://docs.docker.com/engine/install/) for detailed instructions. |
| 27 | + |
| 28 | +If you don't work as root, add your unpriviledged user to the `docker` group. |
| 29 | +Refer to docker documentation on |
| 30 | +[how to manage docker as a non-root user](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) |
| 31 | + |
| 32 | +!!! note |
| 33 | + |
| 34 | + docker-compose comes in two flavor. The first, v1, is a serapate python |
| 35 | + executable called `docker-compose`, the second, v2, is a plugin to the |
| 36 | + `docker` command called with `docker compose` (with a space instead of a |
| 37 | + dash between `docker` and `compose`). |
| 38 | + |
| 39 | + In this documentation, we will use the newer `docker compose` version. |
| 40 | + If you still use the old separate executable, remplace all `docker compose` |
| 41 | + occurences with `docker-compose` |
| 42 | + |
| 43 | +You also need a domain name or a subdomain under which all your cozy instances |
| 44 | +will reside. For example, if you want all your cozy instances under the |
| 45 | +`domain.example` domain. Configure your domain to point to your server in your |
| 46 | +domain's DNS: |
| 47 | + |
| 48 | +```dns |
| 49 | +@ IN A <your server IP> |
| 50 | +* IN A <your server IP> |
| 51 | +``` |
| 52 | + |
| 53 | +If you prefer tu use a subdomain of your main domain, in case you use it for |
| 54 | +anything else, simply create DNS entries pointing to your server for that |
| 55 | +subdomain. For exmaple if you want all your instances to be located under |
| 56 | +the `cozy` subdomain of your `domain.example` domain, you need to add a |
| 57 | +wildcard dns entry to your server like this: |
| 58 | + |
| 59 | +```dns |
| 60 | +cozy IN A <your server IP> |
| 61 | +*.cozy IN A <your server IP> |
| 62 | +``` |
| 63 | + |
| 64 | +## Clone cozy-stack docker-compose repository |
| 65 | + |
| 66 | +```bash |
| 67 | +sudo git clone https://github.com/cozy/cozy-stack-compose.git /opt/cozy |
| 68 | +sudo chown -R `whoami`: /opt/cozy |
| 69 | +``` |
| 70 | + |
| 71 | +## Configuration |
| 72 | + |
| 73 | +Copy the configuration file `env.template` file to `.env` |
| 74 | + |
| 75 | +```bash |
| 76 | +cd /opt/cozy |
| 77 | +cp env.example .env |
| 78 | +``` |
| 79 | + |
| 80 | +and edit this `.env` file to configure your environment. |
| 81 | + |
| 82 | +You should at least edit the following variables: |
| 83 | + |
| 84 | +- `DOMAIN`: The domain under which all your instances will be served. |
| 85 | + In our example, it's `domain.example` or `cozy.domain.example` if you use |
| 86 | + a subdomain. |
| 87 | +- `ACME_EMAIL`: The email under which you want the TLS certificates to be |
| 88 | + issued with Let's Encrypt |
| 89 | +- `COUCHDB_PASSWORD`: Generate and define a strong password for cozy-stack to |
| 90 | + connect to CouchDB |
| 91 | +- `COZY_ADMIN_PASSPHRASE`: The cozy-stack administrative password. Generate |
| 92 | + and define a strong admin password. If unset a random password will be chosen |
| 93 | + and shown in stack logs. If you want cozy-stack cli to ask for the password |
| 94 | + everytime, you can undefine this variable and restart container after the |
| 95 | + first run |
| 96 | + |
| 97 | +## Starting the environment |
| 98 | + |
| 99 | +You can then start with |
| 100 | + |
| 101 | +```bash |
| 102 | +cd /opt/cozy |
| 103 | +docker-compose up -d |
| 104 | +``` |
| 105 | + |
| 106 | +## Create instance |
| 107 | + |
| 108 | +To execute `cozy-stack` commands inside the docker container, you can use the |
| 109 | +provided `cozy-stack.sh` script that executes the `cozy-stack` command inside |
| 110 | +the docker container with provided arguments. |
| 111 | + |
| 112 | +You can execute any `cozy-stack` command by simply replacing `cozy-stack` with |
| 113 | +`./cozy-stack.sh` |
| 114 | + |
| 115 | +For example: |
| 116 | + |
| 117 | +```bash |
| 118 | +cd /opt/cozy |
| 119 | +./cozy-stack.sh status |
| 120 | +``` |
| 121 | + |
| 122 | +To create your first instance: |
| 123 | + |
| 124 | +```bash |
| 125 | +cd /opt/cozy |
| 126 | +./cozy-stack.sh instances add \ |
| 127 | + --apps home,banks,contacts,drive,notes,passwords,photos,settings,store \ |
| 128 | + |
| 129 | + --locale fr \ |
| 130 | + --tz "Europe/Paris" \ |
| 131 | + --passphrase YourStrongP@ssw0rd \ |
| 132 | + myinstance.domain.example |
| 133 | +``` |
| 134 | + |
| 135 | +And then direct your browser to <https://myinstance.domain.example>. |
| 136 | + |
| 137 | +The first time you access an application it will take a handful of seconds for |
| 138 | +the Caddy reverse proxy to automatically generate the TLS certificate. |
| 139 | + |
| 140 | +All data will be stored in a `volumes` subdirectory. You can backup them. |
| 141 | + |
| 142 | +## Going further |
| 143 | + |
| 144 | +### Debugging |
| 145 | + |
| 146 | +You can list running containers with their state with |
| 147 | + |
| 148 | +```bash |
| 149 | +cd /opt/cozy |
| 150 | +docker compose ps |
| 151 | +``` |
| 152 | + |
| 153 | +In case something gets wrong, you can access logs from docker compose. |
| 154 | + |
| 155 | +**cozy-stack logs** |
| 156 | + |
| 157 | +```bash |
| 158 | +cd /opt/cozy |
| 159 | +docker compose logs stack |
| 160 | +``` |
| 161 | + |
| 162 | +**Caddy reverse proxy** |
| 163 | + |
| 164 | +```bash |
| 165 | +cd /opt/cozy |
| 166 | +docker compose logs caddy |
| 167 | +``` |
| 168 | + |
| 169 | +**CouchDB logs** |
| 170 | + |
| 171 | +```bash |
| 172 | +cd /opt/cozy |
| 173 | +docker compose logs couchdb |
| 174 | +``` |
| 175 | + |
| 176 | +### Stopping environment |
| 177 | + |
| 178 | +Simply run |
| 179 | + |
| 180 | +```bash |
| 181 | +cd /opt/cozy |
| 182 | +docker compose down |
| 183 | +``` |
| 184 | + |
| 185 | +### Upgrading |
| 186 | + |
| 187 | +To upgrade to latest version, you need to stop the whole environment, pull the |
| 188 | +new images and restart it. Carefully plan the upgrade as it will lead to |
| 189 | +service interruption during the upgrade. |
| 190 | + |
| 191 | +```bash |
| 192 | +cd /opt/cozy |
| 193 | +docker compose down |
| 194 | +git pull |
| 195 | +docker compose pull |
| 196 | +docker compose up -d |
| 197 | +``` |
0 commit comments