Docker and Silverstripe CMS [Outdated]


Improve manageability and consistency of development environments and streamline Silverstripe CMS deployment with Docker and automated deployments using Buddy

Code repository

Setting up your local environment


  1. Install and run Docker for Linux or Docker Desktop for Mac/ Windows from https://docs.docker.com/get-docker/.
  2. Create a folder in which you will set up your project.
  3. Create another folder called mysilverstripeapp that will hold your Silverstripe application in the project folder.
  4. Add a Dockerfile and a docker-compose.yml with the code bellow to your folder.

This Dockerfile will create an image with Silverstripe CMS's PHP requirements and composer (optional). Composer is used, among other things, to install dependencies and may be omitted from the Dockerfile provided that the Docker host has access to composer elsewhere.

This docker-compose file creates a Silverstripe container on port 8080 that will use the Silverstripe CMS project in the myapp/mysilverstripeapp directory as well as a MySQL-instance with persistant data. The typical .env file for Silverstripe CMS is replaced by the environment variables in docker-compose file.

Developing in your new environment


A new Silverstripe CMS project can be created running the following in the same folder as your Dockerfile and docker-compose file.

docker-compose run --rm silverstripe composer create-project silverstripe/installer .

Running the following will start your Silverstripe application and make it accessible at localhost:8080

docker-compose up -d --build

PHP dependencies can be installed by running

docker-compose run --rm silverstripe composer require [...]

Preparing your production environment


Add the following Dockerfile.prod and docker-compose-prod files to your folder.

The following Dockerfile creates a container with composer that installs the project dependencies and then generates an image that contains the Silverstripe application.

This docker-compose-prod file creates a Silverstripe container on port 80 that will use the Silverstripe CMS image that was built by the Dockerfile.prod file. The Silverstripe assets volume ensures persistent storage of files uploaded to the CMS. The sensitive environment variables are moved to separate environment files that can be stored on the server.

Setting up a droplet on DigitalOcean


  1. Create an account on DigitalOcean.
  2. Click on create and select Droplet.
  3. Under Choose an image, click on Marketplace and select Docker.
  4. Choose the appropriate plan, region, authentication method and enter a name for the droplet.
  5. Click on Create droplet.
  6. SSH into the created droplet and create /root/app directory. This is where the application will be deployed.
  7. Create a /root/env-files/ and add the following files.

Automating deployments using Buddy works


  1. Create and account on Buddy works.
  2. Create a new project on Buddy works and link it to your repository.
  3. Add a new pipeline. Enter a name and select when the deployment should be triggered and which branch/ tag it should be tied to.
  4. Add an RSync action.
  5. Enter the droplet access credentials and set the remote path to /root/app.
  6. Add an SSH action.
  7. Enter the droplet access credentials and set the working directory to /root/app.
  8. Add the commands bellow to the action.
  9. Push your code and run the pipeline.

The Silverstripe application should now be available using the droplets IP address. All that is left is adding the appropriate DNS record(s) and preferable SSL certificate(s).