Kamal smooths over a lot of the rough edges of hosting an app on a server you control. One problem that needs a little more sanding is that kamal requires us to have a docker registry to push our images to. Unless you're doing open source, you probably want these app images to stay private! Until we get an official answer from kamal here's a workaround that I've been using.
Be aware that you still need some kind of public image hosting due to limitations in kamal as of version 2.2.2. There's a hack at the bottom of this document to work around this limitation as well.
- Change values in the deploy config to suit your setup
- Run
kamal deploy - Run
kamal htpasswd-set <username> <password>to set as many credentials as you need or rotate keys - Enjoy!
On your local machine…
docker run --volume ./auth:/auth --rm --entrypoint htpasswd httpd:2 -Bb /auth/htpasswd <username> <password>docker run --volume ./auth:/auth --rm --port 5000:5000 -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd registry:2- In another terminal
ngrok http 5000 - Copy the ngrok url, and place it in your kamal config under
registry/server - Ensure the credentials you gave it are configured in your kamal secrets
- Run the steps to deploy
- Optional: Replace the ngrok url with your freshly deployed docker registry
- I also have a video about this on YouTube