docker4drupal
docker4drupal copied to clipboard
Using drush site aliases
Is it possible to use drush site aliases with the php docker container? + How would such a configuration look like? Asking this question as you can not exactly SSH into a container.
Thanks.
It is certainly possible. All you need is to load each Drush alias file as a volume pointing to the user's .drush
directory in the container. Assuming you have a multisite installation with two sites called "site1" and "site2" and you have a local directory "drush" with your alias files called "site1.aliases.drushrc.php" and "site2.aliases.drushrc.php" you'll need to add something like this in the php container volume definition:
volumes:
- ./drush/site1.aliases.drushrc.php:/home/wodby/.drush/site1.aliases.drushrc.php
- ./drush/site2.aliases.drushrc.php:/home/wodby/.drush/site2.aliases.drushrc.php
- .. other volume definitions...
The contents of the site1.aliases.drushrc.php should be something like this (assuming that site1's directory is located under sites/site1.com
:
<?php
/**
* @file
* Site alias for site1.com
*/
$aliases["site1"] = array(
'root' => '/var/www/html',
'uri' => 'site1.com',
'#name' => 'site1.com',
);
Then, from /var/www/html
:
drush @site1 <command>
Thanks @proteo however this still means that I need to be running the drush command from inside the container? Would this be possible from outside the container as well?
The real usage would actually be to sync files/database from different environments.
Uhmm.. I think the easiest way would be creating a bash script that executes the drush commands for you, load it as a volume (make sure it has proper exec permissions) in your container then do something like this from your host:
docker exec <container-name> /path/to/the/script.sh
Make sure to start your bash script with:
#!/bin/sh
Or prepend the exec command with /bin/bash
:
docker exec <container-name> /bin/bash /path/to/the/script.sh
Actually currently doing something like the above example, however this will not permit full usage of using drush aliases. E.g. sql-sync
I have noticed that there is a similar discussion going on here https://github.com/drush-ops/drush/issues/1910