GRAV CMS DEVELOPER

WhatsApp/Signal: +91-953-66666-77
Email ID: hello@gravdeveloper.com
Use Docker to Set Up a Local Development Environment for Your Grav CMS Project

Use Docker to Set Up a Local Development Environment for Your Grav CMS Project

  • Date: May 26, 2025
  • Tags: Grav Cms and Docker

Use Docker to Set Up a Local Development Environment for Your Grav CMS Project

Setting up a local development environment for Grav CMS using Docker streamlines your workflow by ensuring consistency, portability, and ease of deployment. This guide walks you through the process, from setting up your project directory to running Grav CMS in a Docker container.

Prerequisites Before you begin, ensure you have the following installed on your system:

Docker: A platform to develop, ship, and run applications inside containers.

Docker Compose: A tool for defining and running multi-container Docker applications.

If you haven't installed these yet, refer to the official Docker installation guides for your operating system.

Step 1: Create the Project Directory

Start by creating a dedicated directory for your Grav CMS project:

Type in Bash:

  • mkdir grav-cms-docker
  • cd grav-cms-docker

This directory will house all related files, including the Docker setup.

Step 2: Download and Prepare Grav CMS

Download the latest version of Grav CMS using the wget command:

Type in Bash:

  • wget https://getgrav.org/download/core/grav-admin/latest -O grav-admin.zip

Unzip the downloaded file and rename the extracted folder:

Type in Bash:

  • unzip grav-admin.zip
  • mv grav-admin grav
  • rm grav-admin.zip

Now, your Grav CMS files are located in the grav directory.

Step 3: Create the Dockerfile

A Dockerfile contains a set of instructions to build a Docker image. Create a Dockerfile in your project root:

Type in Bash:

  • touch Dockerfile

Open the Dockerfile in your preferred text editor and add the following content:

  • FROM php:8.1-apache
  • RUN apt-get update && apt-get install -y \
  • unzip \
  • && docker-php-ext-install pdo pdo_mysql
  • COPY ./grav /var/www/html
  • RUN chown -R www-data:www-data /var/www/html
  • EXPOSE 80

This Dockerfile sets up a PHP 8.1 environment with Apache, installs necessary extensions, copies your Grav files into the container, and sets appropriate permissions.

Step 4: Create the docker-compose.yml File

Docker Compose allows you to define and manage multi-container Docker applications. Create a docker-compose.yml file in your project root:

Type in Bash:

  • touch docker-compose.yml

Add the following content to the file:

yaml----

  • version: '3.8'
  • services:
  • grav:
  • build: .
  • ports:
    • "8080:80"
  • volumes:
    • ./grav:/var/www/html
  • restart: unless-stopped

This configuration builds the Docker image using the Dockerfile, maps port 8080 on your host to port 80 in the container, mounts the grav directory for persistent storage, and ensures the container restarts unless stopped manually.

Step 5: Build and Run the Docker Container

With your Dockerfile and docker-compose.yml in place, build and start your Grav CMS container:

Type in Bash:

  • docker-compose up -d

This command builds the Docker image and runs the container in detached mode.

Step 6: Access Grav CMS Once the container is running, you can access your Grav CMS instance by navigating to http://localhost:8080 in your web browser.

Additional Tips Stopping the Container: To stop the running container, use:

Type in Bash:

  • docker-compose down

Viewing Logs: To view logs from the container, use:

Type in Bash:

  • docker-compose logs -f

Rebuilding the Container: If you make changes to the Dockerfile or docker-compose.yml, rebuild the container with:

Type in Bash:

  • docker-compose up -d --build

Feel free to reach out if you'd like to make changes to your Grav website or simply chat about your Grav project. I'm available for a free consultation!