Deploy a Docker application with Kamal

Reading time:   2 min


Kamal is a developer tool that will allows you to deploy your Docker applications to cloud VMs from your command line.

Today I'll show you how to deploy a Docker application (in my case a simple FastAPI app) to a VPS on Contabo. Most of the blog posts and articles talk about Hetzner Cloud, but Contabo is as relaible and cheap and has more RAM on standard VPS servers (6GB vs 4GB).

So, first of all we spin off our Cloud VPS instance on Ubuntu; I chosed the 20.04 version.

Looking around the web, I found a very useful Ansible playbook to automatically optimize and secure your servers for Kamal (Ubuntu only):

To run this script, first install Ansible according to the official documentation.

Before entering in the kamal stuff, there are some more things that need to be done in the server.

First, to avoid the error "permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock", according to this blog post, you need to create the docker group (if it doesn't exist) and add your user to the docker group:

sudo groupadd docker
sudo usermod -aG docker ${USER}

and then verify that you can run docker commands:

docker run hello-world

Another important point is to create a docker private network for Kamal services to work:

docker network create --driver bridge private

If you use Cloudflare, it's also important to verify your SSL settings. My settings were on "Flexible", and I wasn't able to access the web app, too many redirections. Setting it to Full, solved the problem:


When everything is fine, go to your project directory and type:

kamal init

This will create a config/deploy.yml file in your project folder. This is mine:

Follow the Kamal documentation, and run these commands:

kamal setup
kamal deploy

A very useful post on the same topic can be found here.


Sounds interesting ?

Contact me to discuss your need.

Thomas Cenni
Thomas Cenni is an Electronic Engineer with more than 20 years of experience in program management and software engineering. Passionate about software engineering and development, experienced leader with a strong background in the end-to-end lifecycle of product development, he is also a certified SAFe® 6 agilist. Entrepreneur, credible and highly motivated, he showed a great ability to adapt to various cultures and countries, assuming different roles and challenges in Italy, Brazil and France. He is fluent in English, French, Italian and Brazilian Portuguese.