When it comes to running a virtualised development environment there are two highly debated options – Vagrant or Docker. Both of these have their pros and cons and for all intents and purposes, Laravel Homestead is still a great option for developing a Coaster project locally. However, for those who would rather use Docker we have come up with a solution.
What is Docker?
If you’re already familiar with Docker then you can probably skip this bit. Docker uses containers that share resources with the host, instead of dedicated resources. The advantage of this is that multiple containers can be run simultaneously while using very little RAM. The same sort of setup with Vagrant would result in your PC quickly running out of memory.
New containers can be instantiated instantly without the need of having to wait for a virtual machine to start up and provision each time you make any changes. Docker also allows you to compartmentalise your app’s different services such as MySQL, Redis and the main web stack.
Docker is certainly worth having a look at if you are currently unfamiliar with it. The only disadvantage of it is that it can be considerably harder to get up and running compared with Vagrant.
Getting started with Docker is a lot quicker and easier if you use images that are already provided. In this instance we have put together a docker-compose.yml file and Dockerfile that can be copied and pasted into your site’s directory. This includes images for php7-fpm, MySQL 5.7 and Nginx. To download and run the container simply enter the commands below:
git clone https://github.com/Web-Feet/coasterdock.git <your_directory>
docker-compose run -d
This command may take awhile depending on your internet connection, or whether you already have local images. If everything has gone as it should, head on over to localhost and run the Coaster install. When asked for database details use homestead for the user and database name; and secret as the password.
Feel free to edit the docker-compose.yml file as you wish. You could for instance change the port for Nginx or use a separate MySQL container.
We hope this tutorial has helped those who are new or old to the world of Docker, and were looking to get started with Coaster. If you run into any trouble feel free to comment or post on our forum. Docker can be daunting at first, especially compared to a simple setup such as MAMP, WAMP or Homestead but in the end it is certainly worthwhile. You can configure environments to the exact specification of your host to ensure maximum compatibility.