DEV Community

Cover image for Learn How to Dockerize Strapi v4
Strapi for Strapi

Posted on • Originally published at strapi.io

Learn How to Dockerize Strapi v4

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, 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 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:

Another option is to use Docker to facilitate the deployment to various cloud providers, or Kubernetes managed services such as Amazon EKS, Microsoft 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 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 as a courtesy to the community.

What is Dockerize?

Dockerize is a CLI tool built by Simen Daehlin, 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 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, 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 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! 🧑‍🚀

Top comments (1)

Collapse
 
bigfish258 profile image
hutu zhu

how to deploy to render???