How to use cozy cloud in a persistent way with docker.
First, simply creating a docker container with cozy running in it can be done this way.
dockrer run -d --restart=always --name cozy -p 6500:443 cozy/full
-d makes it run in background (you can remove it to see the logs at startup, but you can also use docker logs cozy
to see them either way).
--restart=always means that if the docker service is restarted, or even the server, the container will be restarted right away, making for less maintainance for you.
--name is cool to find your container more easily in the list of existing containers (docker ps -a
), if you don't give that, a random (but usually funny) name will be generated.
-p is there to expose the https port of cozy to a port of your choice, so you can actually connect to it when connecting to your server on this port, usually you'll use an http proxy to redirect a subdomain or whatever on it (i didn't manage to use an apache location, so i used a cloud.something.tld
subdomain).
Last is the name of the image you want to use, this image is provided by the cozy cloud team and works well.
Now, you can start and stop this container at will, but it's not the safest option out there, the word of mouth in the docker community (and for very good reasons), is that your containers should be stateless, i.e, they shouldn't contain changing files, so that you can actually destroy and recreate containers at will, without losing data. If you start the container as described above, you don't know where your data is stored, and if you destroy the container (for example, because you want to run a more recent version of the cozy image), you lose them, not fun :(.
Fixing it, however, is quite easy, even if you started a docker container this way and started putting data in it, all is not lost, you can switch to the alternate method.
if you use the docker inspect cozy
command, you'll see a Mounts
section in the json document that is returned (if you have jq
handy, you can use it to see only that docker inspect cozy|jq ".[].Mounts"
). This section will show you 3 mount points, "/var/lib/couchdb", "/etc/cozy", "/usr/local/cozy". By default, they'll be linked to temporary, random, locations, you can actually go to these locations on your disk and see your data, they'll just disappear, if you have data to save before destroying your container, it's a good idea to copy the content of these "sources" to somewhere else.
Now to start a cozy container using known directories on your disk, you should prepare 3 places to host these 3 mounts points, and bind them using the -v
flag.
Let's say i used /data/cozy on my host system, with couchdb, etc, local, dirs in it.
dockrer run -d --restart=always --name cozy -p 6500:443 -v /data/cozy/couchdb:/var/lib/couchdb -v /data/cozy/etc:/etc/cozy -v /data/cozy/local:/usr/local/cozy cozy/full
And voilà… now even if you manage to break your container, or delete it for whatever reason, you can always start a new instance with your old data, because it's safe on your host system (and you can also use any backup system to regularly save it).
Nice tutorial <3