I have a droplet setup on Digital Ocean with two docker containers, one for Drupal (using modified alpine-drupal8 image) and another running a simple mysql server.
I am able to run drush commands on this container by connecting over ssh into the droplet and running docker exec -it <container_name> /bin/sh
I have also set up an ssh server (listening on port 2222 on the same ip address) on the container itself with a little port forwarding:
ssh root@<droplet_ip> -p 2222 # Connects from remote dev machine to drupal container using ssh key
My sites/default/drush/aliases.drushrc.php file:
<?php
$aliases['container'] = array(
'root' => '/usr/share/nginx/html',
'uri' => 'http://default',
'path-aliases' =>
array (
'%drush' => '/usr/local/bin/drush',
'%site' => 'sites/default/',
'%files' =>'sites/default/files/',
'%modules' =>'modules/'
),
'remote-host' => '<droplet_ip>',
'remote-user' => 'root',
'ssh-options' => '-p 2222',
);
?>
Starting an ssh session with the drush alias is working:
$ drush @container ssh
186203cca:/usr/share/nginx/html# ### Connected to ssh session in droplet
186203cca:/usr/share/nginx/html# which drush
/usr/local/bin/drush
186203cca:/usr/share/nginx/html# drush status
Drupal version : 8.1.8
Site URI : http://default
Database driver : mysql
Database hostname : <removed>
Database port : <removed>
Database username : <removed>
Database name : <removed>
Drupal bootstrap : Successful
Drupal user :
Default theme : <removed>
Administration theme : seven
PHP configuration : /etc/php7/php.ini
PHP OS : Linux
Drush script : /usr/local/bin/drush
Drush version : 8.1.3
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Install profile : standard
Drupal root : /usr/share/nginx/html
Drupal Settings File : sites/default/settings.php
Site path : sites/default
File directory path : sites/default/files
Temporary file directory path : /tmp
Sync config path : sites/default/files/config_vxs7qxuAqrfCtOXdbGYLvLAIKl1_bN4J_BvmrEn1l1EUIsn4Du_CKck2QWYSmkNDgUVfdZUZVQ/sync
However, I still can't seem to run actual drush commands:
$ drush @container status
env: can't execute 'drush': No such file or directory
My theory is that the port forwarding is not working correctly, and drush is trying to run on the container, not the droplet
This may be related to my issue: Why does drush say "command not found" when I try to execute remote commands?
Update:
A little more testing and I found out I can use drupal console without issues, so it seems this is isolated to drush only:
$ drupal @container cr all
Rebuilding cache(s), wait a moment please.
[OK] Done clearing cache(s).