I recently had reason to switch over to using Docksal for a project, and on the whole I really like it as a good easy solution for getting a project specific Drupal dev environment up and running quickly. But like many dev tools the docs I found didn’t quite cover what I wanted because they made a bunch of assumptions.
Most assumed either I was starting a generic project or that I was starting a Pantheon specific project – that I already had Docksal experience. In my case I was looking for a quick emergency replacement environment for a long-running Pantheon project. So I wanted to install Docksal from scratch for a Pantheon project.
Fairly recently Docksal added support for a project init command that helps setup for Acquia, Pantheon, and Pantheon.sh, but pull init isn’t really well documented and requires a few preconditions.
Since I had to run a dozen Google searches, and ask several friends for help, to make it work I figured I’d write it up.
First follow the basic Docksal installation instructions for your host operating system. Once that completes, if you are using Linux as the host OS log out and log back in (it just added your user to a group and you need that access to start up docker).
Add Pantheon Machine Token
Next you need to have a Pantheon machine token so that terminus can run within the new container you’re about to create. If you don’t have one already follow Pantheon’s instructions to create one and save if someplace safe (like your password manager).
Once you have a machine token you need to tell Docksal about it. There are instructions for that (but they aren’t in the instructions for setting up docksal with pull init) basically you add the key to your docksal.env file:
Also if you are using Linux you should note that those instructions linked above say the file goes in
$HOME/docksal/docksal.env, but you really want
$HOME/.docksal/docksal.env (note the dot in front of docksal to hide the directory).
Setup SSH Key
With the machine token in place you are almost ready to run the setup command, just one more precondition. If you haven’t been using docker or docksal they don’t know about your SSH key yet, and pull init assumes it’s around. So you need to tell Docksal to load it but running fin ssh-key add.
If the whole setup is new, you may also need to create your key and add it to Pantheon. Once you have done that, if you are using a default SSH key name and location it should pick it up automatically (I have not tried this yet on Windows so mileage there may vary – if you know the answer please leave me a comment). It also is a good idea to make sure the key itself is working right but getting the git clone command from your Pantheon dashboard and trying a manual clone on the command line (delete once it’s done, this is just to prove you can).
Run Pull Init
Now finally you are ready to run fin pull init:
fin pull init --hostingplatform=pantheon --hostingsite=[site-machine-name] --hosting-env=[environment-name]
Docksal will now setup the site, maybe ask you a couple questions, and clone the repo. It will leave a couple things out you may need: database setup, and .htaccess.
Add .htaccess as needed
Pantheon uses nginx. Docksal’s formula uses Apache. If you don’t keep a .htaccess file in your project (and while there is not reason not to, some Pantheon setups don’t keep anything extra around) you need to put it back. If you don’t have a copy handy, copy and paste the content from the project repo: https://git.drupalcode.org/project/drupal/blob/8.8.x/.htaccess
Finally, you need to tell Drupal where to find the Docksal copy of the database. For that you need a settings.local.php file. Your project likely has a default version of this, which may contain things you may or may not want. Docksal creates a default database (named default) and provides a user named…“user”, which has a password of “user”. The host’s name is ‘db’. So into your settings.local.php file you need to include at the very least:
array( 'default' => array( 'database' => 'default', 'username' => 'user', 'password' => 'user', 'host' => 'db', 'port' => '', 'driver' => 'mysql', 'prefix' => '', ), ), );
With the database now fully linked up to Drupal, you can now ask Docksal to pull down a copy of the database and a copy of the site files:
fin pull db
fin pull files
In the future you can also pull down code changes:
fin pull code
Bonus point: do this on a server.
On occasion it’s useful to have all this setup on a remote server not just a local machine. There are a few more steps to go to do that safely.
First you may want to enable Basic HTTP Auth just to keep away from the prying eyes of Googlebot and friends. There are directions for that step (you’ll want the Apache instructions). Next you need to make sure that Docksal is actually listing to the host’s requests and that they are forwarded into the containers. Lots of blog posts say
DOCKSAL_VHOST_PROXY_IP=0.0.0.0 fin reset proxy. But it turns out that fin reset proxy is out of date, instead you want:
DOCKSAL_VHOST_PROXY_IP=0.0.0.0 fin system reset.
Next you need to add the vhost to the docksal.env file we were working with earlier:
fin up to get Docksal to pick up the changes (this section is based on these old instructions).
Now you need to add either a DNS entry someplace, or update your machine’s /etc/hosts file to look in the right place (the public IP address of the host machine).