Skip to content

Instantly share code, notes, and snippets.

@mortenson
Last active January 7, 2020 11:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenson/48d16568147a710bedf94506f837733a to your computer and use it in GitHub Desktop.
Save mortenson/48d16568147a710bedf94506f837733a to your computer and use it in GitHub Desktop.
Quick way to proxy Drush commands to your Docker container
#!/bin/bash
# Save this to a file named "drush" (not "drush.sh") and put it in the same
# directory as your docker-compose file. Replace "SERVICE" with your docker
# container's name.
# Now every time you run "drush" from this directory, it runs drush inside
# your container instead. Cool!
docker-compose exec SERVICE drush $@
@rodrigoaguilera
Copy link

Doesn't "this directory" need to be in the $PATH ?

@mortenson
Copy link
Author

I don't think so, Drush is clever and will prefer local versions of the drush binary if it detects one. So you may start running drush globally (/usr/local/bin), but that will find this drush script and pass everything to it instead.

@marcoscano
Copy link

As an alternative approach, I've been using what Janez suggested here: https://janezurevc.name/drupal-dev-environment-on-docker, having a drush container linked to the web container. It's been working great for me so far.

@mortenson
Copy link
Author

Nice - I was doing something similar but got really tired of writing docker-compose run --rm drush, or even aliases like docker-drush. My brain still thinks drush should always work if I'm in a webroot, even if that webroot is mounted as a volume in a docker container, 😄

@leymannx
Copy link

leymannx commented Jan 7, 2020

You are a goddamn genius! Thanks for sharing. 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment