Learn How to Dockerize Strapi v4
Tags: strapi, docker, cluster, webdev
Published: 2022-12-14 18:31:49

**Author: @eventyret**

As an open-source Headless CMS, Strapi provides many deployment options from traditional hosting servers or your preferred hosting provider. 

It was recently announced the [Strapi Cloud beta program](https://strapi.io/blog/announcing-strapi-cloud-beta), a hosted Content Management platform. Strapi announced when will be available and more about what is coming. So if you don't want to deploy Strapi by yourself, join the [waitlist](https://strapi.io/cloud) to soon access the easiest way to host your Strapi application and get additional benefits! 

In the meantime, the Strapi developer documentation includes several step-by-step how-to guides for deploying Strapi on the most popular hosting providers: 

- [Deploying on AWS EC2](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/amazon-aws.html)
- [Deploying on Azure](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/azure.html)
- [Deploying on DigitalOcean App Platform](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/digitalocean-app-platform.html)
- [Deploying on DigitalOcean Droplets](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/digitalocean.html)
- [Deploying on GCP's App Engine](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/google-app-engine.html)
- [Deploying on Heroku](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/heroku.html)

Another option is to use Docker to facilitate the deployment to various cloud providers, or Kubernetes managed services such as [Amazon EKS](https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html), [Microsoft AKS](https://learn.microsoft.com/en-us/azure/aks/), or others. 

In this post, we'll take a closer look at what Docker is. Learn how to build custom Docker containers with an existing Strapi project and introduce an open-source community tool called Dockerize, which can assist you in deploying Strapi to various cloud providers using Docker. 

## What are Docker and Docker Compose? 

If you need to become more familiar with Docker and Docker Compose, check out [this article](https://strapi.io/blog/what-is-docker-compose-all-you-need-to-know) to learn more about it and how it can help ship your applications to your favorite Cloud providers. 

## Run Strapi in a Docker Container

Strapi does not build any official container images because you can build many different types of applications for various use cases using Strapi. However, we provide [Docker documentation for Strapi](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/installation/docker.html) as a courtesy to the community. 

## What is Dockerize?

Dockerize is a CLI tool built by [Simen Daehlin](https://twitter.com/eventyret), Strapi Community Organization Member. 

This tool aims to simplify the life of developers who want to deploy Strapi with Docker. After the user answers some questions, it will generate files for their Strapi project.

It's a simple one-time run tool that will generate a `Dockerfile, Dockerfile.prod` (if you choose production or both), and `docker-compose`. All ready to go and configured to the user's needs.

This tool makes development and deploying with docker super simple, run the tool, answer questions, and off you go to the races! Under the hood, the tool will consider what database is wanted and currently supporting: MariaDB, MySQL, and PostgreSQL.

It will auto-detect `YARN` or `NPM` and use the tool according to what is being used by the project. It generates and backs up `database.js/ts` for you if this is detected and generates config environment folders with files for you.

Last but not least, it also generates values that have been asked for your `.env` file, which docker-compose can use. It also has CLI integration by passing CLI Flags so other CLI tools can work with it.

## Strapi Dockerize Roadmap

Currently, I am working on changes to `server.js/ts` where we can inject and set up CORS as this seems to be a known issue for users. And detect if the project is a Strapi project; if not, we will start the Strapi CLI to simplify things for a user.

## Why did I build this tool?

I started work on this as there needed to be more info about Strapi and Docker. In Strapi v3, an [official Docker image of Strapi](https://hub.docker.com/r/strapi/strapi/) was downloaded more than 10M times. It was "a nice to have" for many people in the Strapi Community, yet not a good fit for many people who needed to customize their images. 

Dockerize gives developers the power to customize their images to their applications' needs and requirements. This also enhances security and saves Strapi as a company from maintaining a docker image, as each user can create their own image.

I wrote a blog post on how to [dockerize Strapi v4 for development](https://blog.dehlin.dev/docker-with-strapi-v4), and after 40k visits, I realized that there was definitely a need for a tool to automate some of the work. 

As a result, [Deployify](https://github.com/strapi-community/strapi-tool-deployify) was born with the help of other developers. Making a simple tool to deploy Strapi to the cloud. I'm thrilled that this has become people's standard when using templates in Docker for images! 🧑‍🚀