SilverStripe 4 on Docker

SilverStripe on Docker is pretty simple. Containerisation can help with solving a very common problem that happens to many developers on a daily basis, which is set up your environment in order to start working on a product itself. There are many cases in which you spend more time setting that up than working on a product. That is what containerisation tries to address. According to Docker website, Docker is a set of platform-as-a-service products that use OS-level virtualisation to deliver software in packages called containers.

Now, how to set up SilverStripe for Docker?

There are a couple way to do this. You can create a container and set up the whole environment from scratch, or you can search for existing containers. I found that the most popular at this point are mysql and silverstripe-web. In order to quickly set up those containers pull them down with the following commands:

$docker pull brettt89/silverstripe-web
$docker pull mysql

Now that you have got them, you can quickly set them up using the following commands. For instance, if you want to set that up with PHP 7, here is what you can do:

$docker run -p 3306:3306 --name database -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql
$docker run -p 80:80 -v /path/to/your/code:/var/www/html --link database --name project1 brettt89/silverstripe-web:7.1-platform

An interesting fact is that after you access your localhost in your browser, even if the code is running inside the container, and the code on your IDE is just a copy of what is running, yet a change in that “/path/to/your/code” will be watched and updated as you change it outside the container.

Hope that helps!
Happy coding!

Leave a comment