Long gone are the days when writing code was all you needed to develop awesome apps. Nowadays, developers should be able to use multiple languages, frameworks and architectures – and on top of that – they need to know how to use several tools and products which can make their lives easier.
One of these products (platform as a service – PaaS product to be exact) is Docksal. Docksal is Docker powered environment for web development on macOS, Windows and Linux. Even though there are many other types of Docker based tools, such as Lando or Docker4Drupal, we opted to use Docksal because it is fast, easy to use and well-documented.
Our experienced Drupal developer – Darko Zaric, shares his tips on how you can create a local Drupal 8 development environment by using Docksal.
Docksal commands and usage
To start running things in Docksal, you will need to use the “fin” command. Docksal Fin (fin) is a command line tool for controlling Docksal that simplifies the management of all components. You can find all fin commands in the Docksal documentation, but we wrote down several most frequently used to help you out:
- fin create – Create a new project
- fin up – Configuration re-read and start project services
- fin stop – Stop all or specified project services
- fin restart – Restart project services
- fin db import [file] – Truncate the database and import from SQL dump file
- fin db dump [file] – Dump a database into an SQL dump file
- fin exec <command> – Execute commands or script in `cli` service container (i.e. fin exec ls -la)
Using Drupal 8 composer version environment
Now that you know more about fin commands, you can move on and start creating your project. You can create your project and environment with the “fin project create” command.
When you enter your project name, you can choose the type of project. If you are using Drupal, our recommendation is to use the composer version, because Drupal core and contrib modules are set outside of git and pulled from Composer. It will make your life easier every time you need to review code after updates.
When you confirm that your project details are correct and that you wish to proceed with action, the repository will be cloned from git.
The next step is creating and starting container services.
Once that site initialization is started, it will pull your Composer dependencies, prepare, and install Drupal on your environment.
When everything is finished, your project will be created and ready to use, and you will get admin user credentials and site address.
Working with a project that is already configured on Docksal is easy, you will only need to run command “fin up” and it will start all your project services – making your project ready for use.
Initialization of empty Docksal environment
Docksal has pre-created stacks. The Default Stack includes 3 services: web, db, and cli. Everything that you need to do in order to create an empty environment is to create a project directory and run command “fin config generate” and “fin project start” inside it. As you can see on the screenshot below, web, db and cli containers will be created and the environment will be ready for use, so you can put your project in docroot and keep working with the Docksal in the same way as it is explained in this article.
If you want to add some services to your project, you can do that in .docksal/docksal.yml file. Here is an example for adding Mail Hog because we are adding it to all our projects.
After adding the above mentioned code to your .docksal/docksal.yml you need to run “fin p start” to create mail service. Mail Hog will be available on the address: http://mail.<VIRTUAL_HOST>
Changing the default images
If for any reason you need to set a specific version of image, that is different from Docksal default image, you have available variables that you can use in .docksal/docksal.env file. Also, here you can change the default docroot, virtual host, mysql port… For a full list of the image versions, you can visit Docksal documentation in their help center.
Ready to create your first project using Docksal?
And there you have it – a step by step process on how to create a local Drupal 8 development environment using Docksal. Now it is your turn to do the same.
And if you have any questions or if you want us to help you with your Drupal project, don’t hesitate to contact us.