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:


$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
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?


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).
  • Post your drush alias configuration for the site without any credential or connection information.
    – mradcliffe
    Commented Aug 29, 2016 at 19:46
  • I've made some progress and updated the question.
    – crobicha
    Commented Aug 29, 2016 at 22:01
  • Why u don't just enter your docker container with -> docs.docker.com/engine/reference/commandline/exec
    – DiDebru
    Commented Aug 30, 2016 at 9:14
  • I can enter the container as you describe, or use ssh directly. The problem is that none of the drush alias commands are working
    – crobicha
    Commented Aug 30, 2016 at 14:55
  • The example at github.com/drush-ops/drush/blob/master/examples/… says that the %drush option "points to the folder that the drush script is stored in." but you have set it to the executable.
    – Mike
    Commented Oct 5, 2016 at 6:07

1 Answer 1


So this one threw me for a while this evening as well.

Here's what ended working:

$aliases['docker'] = array(
  'uri' => 'http://localhost:8080',
  'php' => '/usr/bin/php',
  'root' => '/var/www',
  'remote-user' => 'root',
  'remote-host' => '',
  'ssh-options' => '-p 8022 -o PasswordAuthentication=no -i ~/.ssh/id_rsa',
  'path-aliases' =>
  array (
    '%drush' => '/root/.composer/vendor/drush/drush/drush'

The remote host of ended up doing the trick. Seems that if you use localhost or drush doesn't actually try to ssh in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.