Silverstripe CMS Development with Docker


Improve manageability and consistency of development environments and using Docker. Sail CLI makes development easy for developers with all levels of Docker knowledge.

Code repository

Introduction


Sail provides a Docker powered local development experience for Silverstripe CMS that is compatible with macOS, Windows (WSL2), and Linux. Other than Docker, no software or libraries are required to be installed on your local computer before using Sail. Sail's simple CLI means you can start building your Silverstripe CMS application without any previous Docker experience.

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. If you are creating a new Silverstripe project, run
    docker run --rm \
        -u "$(id -u):$(id -g)" \
        -v $(pwd):/opt \
        -w /opt \
        nordenoliver/silverstripe-phpcomposer:php73-composer2 \
        composer create-project silverstripe/installer my-project
  3. Add silverstripe-sail github repository to composer.json.
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/olivernorden-silverstripe/silverstripe-sail"
        }
    ]
  4. Install silverstripe-sail dependency.
    docker run --rm \
        -u "$(id -u):$(id -g)" \
        -v $(pwd):/opt \
        -w /opt \
        nordenoliver/silverstripe-phpcomposer:php73-composer2 \
        composer require olivernorden/silverstripe-sail
  5. Install sail using ./vendor/bin/sail install. This will create a .env and docker-compose.yml file.
  6. Update the following environment variables to suit your project.
    APP_URL. The url that will be used to access your site. All ondocker.dev subdomains will resolve to localhost and be able to utilize ssl.
    THEME_DIR. The directory used for node/npm commands.
    SILVERSTRIPE_WEB_TAG. Silverstripe web server tag. A tag with apache will be required. Available tags
    COMPOSER_VERSION. Composer version. Available tags
    NODE_TAG. Node version. Available tags

Developing in your new environment


Bellow is a collection of useful commands for Silverstripe development.

Bash alias

A shell script is used for interaction with docker compose. It is recommended to add to following shell alias. Alternatively, the commands below can be prefixed with ./vendor/bin/sail instead of sail.

alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'

Starting your development environment

sail up -d

Manage php dependencies

sail composer <install|update|require>

Manage javascript dependencies

sail npm <install|update>

Run dev/build or build tasks

sail cli dev/build
sail cli dev/tasks/...