How to containerize your Ghost application with Docker
In this post I will tell you how to Dockerize a Ghost app and why you should do that if you work in a development team.
Why should you containerize your Ghost app?
When we started developing our Digital Garden theme, the only way we had to work on it as a team was to manually install Ghost on every computer.
We quickly faced issues by working that way.
The first issue was the loss of time we had to install Ghost on every system. We had to fix some bugs and that cost us a significant amount of time in the development process. The second issue was the Ghost app version, the Ghost apps for the development were not the same as the production one, and the only way we had to synchronize our Ghost apps with the production one, was by manually updating every installation, that caused us to lose a lot of time again.
But we found a solution! Dockerize our Ghost development app so that we don't have to struggle with the installation process anymore and we can easily synchronize our Ghost version with the production one.
How did we Dockerized our Ghost development app
First task we had to do was to install Docker on every computer. Those were easy steps because on macOs and Windows we can download the Docker Desktop app which handles the installation process of the Docker Engine among other things we need.
Then all we had to do was to add a "docker-compose.yaml" file inside our Digital Garden theme repository. What does this yaml file do? Take a look!
version: "3.9"
services:
ghost:
container_name: ghost
image: ghost:4.33.1-alpine
restart: "unless-stopped"
ports:
- 2368:2368
environment:
url: http://localhost:2368
NODE_ENV: development
volumes:
- .:/var/lib/ghost/content/themes/digital-garden
- content:/var/lib/ghost/content
volumes:
content:
Basically, this file will pull a Ghost image from the Docker Hub, create a container and install Ghost in it, copy the Digital Garden theme inside of it and finally launch a Ghost instance in local.
As you can see we are pulling a specific version of the image, in our case the "4.33.1" version. This is how we can manage our Ghost version. By simply modifying this value, we can pull a different version of the Ghost image and therefore we can easily synchronize it with the production build of Ghost. And because the Digital Garden theme is sitting in a repository, our development team only had to pull the changes from GitHub and recompose the Docker container to stay updated.
Conclusion
As you can see, it was quite easy to dockerize our Ghost local development app, and now we can easily work on the same version and synchronize with our Ghost production build.