I have been doing my Drupal development in a virtual machine using Virtualbox for some time. When I was working at the office this is just fine, apart from the fact that it is somewhat slow: I start the VM, wait for it to finish, then make an SSHFS connection to the VM, start PhpStorm, and wait again for PhpStorm to stop indexing (which is REALLY slow).
Now that I’m working from home I faced a problem. I can only connect to the git repositories at work using a VPN connection, but when I start the VPN connection I cannot connect to my VM anymore. This makes pushing and pulling to/from the git repositories cumbersome.
In comes Docker4Drupal. It took some figuring out, especially getting multiple projects to work next to one another, but I got it working.
Docker4Drupal is a Docker-based Drupal stack: a set of docker images optimized for Drupal. You can choose Nginx or Apache, Mariadb or Postgres, Drupal 7 or 8, PHP 7.2, 7.3 or 7.4. There is a plethora of other tools you can choose from, like Redis, Varnish or Memcached for caching, Solr, Elasticsearch and Kibana for search, and a lot more.
I’ll start with basic installation and will get to a more sophisticated setup in a later post. I found this very instructive video: https://www.youtube.com/watch?v=aYb8C18HjmY, I’ll describe it below.
You start with using composer:
composer create-project drupal-composer/drupal-project:8.x-dev project_name --no-interaction (this creates a project in the folder
clone drupal-project — and runs
composer install; make sure to rename the project name)
Then you get the Docker4Drupal stuff:
git clone https://github.com/wodby/docker4drupal.git docker_drupal_server
Because you don’t need the git repository stuff:
rm -rf docker_drupal_server/.git
And remove the docker-compose override:
Then copy the Docker4Drupal stuff in the project folder:
cp -R docker_drupal_server/ project_name
Now comes the configuration. Open the
.env file and make the necessary changes, starting with the project name and URL.
You can make choises about the versions for all the components in the other tags.
Once you have completed the configuration, you can start your container:
docker-compose up -d
Now you go to http://drupal.docker.localhost:8000 (change URL to the one used in
.env) and start your Drupal installation.
Since all the folders are on my local machine, I don’t need the VM anymore and I can connect to my git repositories at work while using the VPN connection.
I’ll get to a more specific setup with more than one project in a later post. Also, because I’m using a Mac, I need to use something called docker-sync. This needs some special attention too.