Docker - use drush

Docker - use drush

There are 2 ways to use drush. The first one is install drush in drupal container. Every time you need to run drush, you ssh drupal container and run the command from that. The second one is to pull the drush image and run the drush command with "docker run".

Let's have a look at the first way. If you are using Drupal 7, you may install drush 6 in your Drupal container by adding the followings into Dockerfile.

# Install drush
RUN mkdir -p /usr/src/drush
WORKDIR /usr/src/drush
RUN curl -OL
RUN tar -xvf 6.6.0.tar.gz --strip-components=1
RUN rm 6.6.0.tar.gz
RUN chmod u+x ./drush
RUN ln -s /usr/src/drush/drush /usr/bin/drush

Every time you run drush command, you need to ssh to drupal container by the command below:

# ssh to container
docker exec -it drupalchilli_web_1 bash

Apparently you need to replace "drupalchilli_web_1" with your container name. After that, go to the drupal root directory and run drush command.

The second way won't require Dockerfile change. You just need to docker pull drush image by the following command. For this case, we are downloading a specific version drush 8.

docker pull drush/drush:8

To execute Drush directly, run the container with docker run, mounting the /app volume:

docker run -v $(pwd):/app drush/drush:8 status


blog tag: