CapRover (local kind of Heroku)
Table of Contents
CapRover (local kind of Heroku)
Prerequisite
- server (Ubuntu LTS) and ssh access
- DNS A type record (to the server’s IP)
- e-mail address for HTTPS registration (could be a fake one)
- network ports opened as per CapRover documentation:
ufw allow 80,443,3000,996,7946,4789,2377/tcp; ufw allow 7946,4789,2377/udp;Only 80 & 443 ports need to be opened to the public internet (as per ticket) + 22 for SSH (or whatever the port is).
Installing CapRover
(as per CapRover, NodeJS docs)
sudo fallocate -l 2G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfileecho "/swapfile none swap sw 0 0" >> /etc/fstabsudo swapon --show
wget -O - https://raw.githubusercontent.com/alexander-potemkin/quickies/main/docker_ubuntu.sh | bash# sudo usermod -aG docker `whoami` # only for non-rootsudo snap install node --classic --channel=18sudo npm install -g caprover # clidocker run -p 80:80 -p 443:443 -p 3000:3000 -e ACCEPTED_TERMS=true -v /var/run/docker.sock:/var/run/docker.sock -v /captain:/captain caprover/caprovercurl -4 ifconfig.co #note IP addressvi caprover.jsoncaprover.json template below (doc):
{ "caproverIP": "127.0.0.1", "caproverPassword": "captain42", "caproverRootDomain": "domain_name", "newPassword": "", "certificateEmail": "your@email.com", "caproverName": "captain-01"}Followed by:
caprover setup -c caprover.jsonInteractive (Q&A) setup could be executed via caprover serversetup
Now go to http://IP_address:3000 (note HTTP, without **S**) port, and proceed with captain42 as a default password.
Migrating CapRover
(as per doc).
Rollout a new server as per ‘Installation process’, but without last docker run command, then run the following commands:
sftp server-labelmkdir /captaincp caprover-backup-*.tar /captain/backup.tardocker run -p 80:80 -p 443:443 -p 3000:3000 -v /var/run/docker.sock:/var/run/docker.sock -v /captain:/captain caprover/caproversudo docker ps # compare the output with the initial server[!NOTE] Good instruction is at 2023-07-09 Steps below are moved from there, but not verified / purified.
Install new instance. Make a backup and restore from it.
[!NOTE] Steps below corrupts source system! It will fail with ‘invalid mount config for type “bind”: bind source path does not exist’
Data backup:
docker service ls --format {{.Name}} | while read in; do docker service scale "$in"=0; donedocker ps # to verify - no containers are runningdocker volume lsdocker volume ls --format {{.Name}} | while read in; do echo "$in:" && docker run -v "$in":/volume --rm --log-driver none loomchild/volume-backup backup -v > ""$in"".tbz2; donedocker service ls --format {{.Name}} | while read in; do docker service scale "$in"=1; donesftp with ‘get’ to the source and ‘put’ to the destination, followed by:
docker service ls --format {{.Name}} | while read in; do docker service scale "$in"=0; donedocker ps
ls *.tbz2 | while read in; do echo "$in => "${in%.tbz2}":" && docker run -i -v ${in%.tbz2}:/volume --rm loomchild/volume-backup restore -v -f < "$in"; done # WARNING: '-f' parameter is in place - override
docker volume ls
service docker restart # seems to be a more reliable way to restart# docker service ls --format {{.Name}} | while read in; do docker service scale "$in"=1; doneMake DNS change, otherwise nginx & captain dockers are failing; do deploy of the main app.
DNS configuration
create DNS record like that one:
*.sub-domain A 1H IP address
- At the Dashboard, link with DNS name:
lhk.domain.name - After CapRover updates to HTTPS, at Chrome type
thisisunsafeto ignore invalid SSL certificate. - Enable HTTPS
- Enjoy!
Logs monitoring
Install Dozzle from one click apps, as per this advice: https://github.com/caprover/caprover/issues/1140
Local registry setup
Cluster -> Setup
caprover ls# make sure you're logged in to your instance. It should be in the list.
caprover api# select your server# for path, use /user/registries# for method, use "GET"# for API data JSON string, leave it empty.# the output is like this:{ "registries": [ { "id": "abcd-abcd-abcd-abcd-abcd", "registryDomain": "registry.root.domain.com:996", "registryImagePrefix": "captain", "registryUser": "captain", "registryPassword": "abcd-abcd-abcd-abcd-abcd", "registryType": "LOCAL_REG" } ], "defaultPushRegistryId": ""}GitHub Deployment keys
ssh-keygen -m PEM -t rsa -b 4096 -C projectname , enter ./id_rsa and get the keys.
cat id_rsa and send that to CapRover’s Deployment page
cat id_rsa.pub and deliver that key to GitHub’s Deployment Key (under settings of repository)
Automatic updates with the source code
Gather webhook URL from CapRover settings.
GitHub → Repository → Settings → Webhooks →add it there,
SSL certificate update
#!/bin/bashset -e
echo "Bringing firewall down"/root/firewall_down.sh
echo "Starting renewal task"docker exec `sudo docker ps --filter name=certbot -q` /usr/local/bin/certbot renew # -it for interactive mode
echo "Giving it time to work things out (60 seconds sleep)"sleep 60
echo "Bringing firewall back up"/root/firewall_up.shOne-click app update
https://github.com/caprover/caprover/issues/1008
Troubleshooting CapRover
Cleaning up cache
Don’t do that, unless absolutely required. Can have unexpected side effects.
as per GitHub issue
docker builder prune --allhttps://caprover.com/docs/troubleshooting.html
CapRover logs
docker service logs captain-captain --since 60m --followFrom the server
sudo docker exec -it `sudo docker ps --filter name=srv-captain -q` /bin/shPassword reset
sudo su -apt install jqdocker service scale captain-captain=0cp /captain/data/config-captain.json /captain/data/config-captain.json.backupjq 'del(.hashedPassword)' /captain/data/config-captain.json > /captain/data/config-captain.json.newcat /captain/data/config-captain.json.new > /captain/data/config-captain.jsonrm /captain/data/config-captain.json.new# set a temporary passworddocker service update --env-add DEFAULT_PASSWORD=captain42 captain-captaindocker service scale captain-captain=1Restart CapRover
docker service update captain-captain --forceRemoving CapRover
docker service rm $(docker service ls -q)## remove CapRover settings directoryrm -rf /captain## leave swarm if you don't want itdocker swarm leave --force## full cleanup of dockerdocker system prune --all --forceNotes
I considered Coolify, didn’t it didn’t work well - more details at 2023-10-20, but on a high level - the features doesn’t work as I expected them to work, original installation was not working, MongoDB never started, as I expected.