A set of Ansible playbooks for spinning up Drupal projects with Docker Compose.
Drupal Dockerizer is suitable for spinning up:
- Local development environments (with XDebug support)
- Automated CI builds
- Staging and testing servers
YAY! π₯ You can spin up multiple environments on a single machine!
Drupal Dockerizer works best on Linux (deb-based distributions have been tested).
To spin up a development environment with Drupal Dockerizer on MacOS and Windows you could use virtual machines or remote servers with Linux installed. Take a look at Visual Studio Code Remote development.
In a nutshell Drupal Dockerizer is not more than an Ansible script which automates routine tasks for getting valid docker-compose.yml files.
We just got a fresh Ubuntu 20.04 server. Let's go through a quick tour about creating new Drupal 9 site installation.
Letβs create a local user in order to avoid work under a root account.
groupadd docker
export USERNAME=<username>
useradd -m -G sudo,docker -s /bin/bash $USERNAME
passwd $USERNAME
mkdir /home/$USERNAME/.ssh
curl https://github.com/$USERNAME.keys | tee -a /home/$USERNAME/.ssh/authorized_keys
chown -R $USERNAME:$USERNAME /home/$USERNAME/Letβs install requirements.
apt update
apt -y install ansible composer git unzip docker.io
systemctl enable --now docker.serviceInstall latest docker-compose. Ubuntu repository has a little bit outdated version.
Read more here: https://docs.docker.com/compose/install/.
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-composeNow you are able to connect to your server with your SSH keys or just use su $USERNAME to log into your user account to start configuring Drupal Dockerizer.
mkdir ~/Projects
composer create-project drupal/recommended-project ~/Projects/drupal9 --ignore-platform-reqs --no-interaction
git clone https://github.com/jet-dev-team/drupal-dockerizer.git ~/Projects/drupal9/drupal-dockerizer
cat <<EOT > ~/Projects/drupal9/drupal-dockerizer.yml
---
compose_project_name: drupal9
user_uid: `id -u`
user_gid: `id -g`
drupal_root_dir: $HOME/Projects/drupal9
expose_http_port: 8090
EOT
cd ~/Projects/drupal9/drupal-dockerizer
ansible-playbook up.yml --ask-become-pass
ansible-playbook drush-commands.ymlAs a result you should receive the next directory structure:
.
βββ composer.json
βββ composer.lock
βββ drupal-dockerizer
β βββ CONFIG.md
β βββ LICENSE
β βββ README.md
β βββ ansible.cfg
β βββ db.yml
β βββ default.config.yml
β βββ runtime-drupal9
β βββ drush-commands.yml
β βββ inventory
β βββ up.yml
β βββ requirements.yml
β βββ clean.yml
β βββ stop.yml
β βββ tasks
β βββ templates
β βββ up.yml
βββ drupal-dockerizer.yml
βββ vendor
β βββ ...
βββ web
βββ index.php
βββ ...You are done. You can access your fresh Drupal 9 site by visiting your IP address on port 8090.
There is no magic! It is just a docker-compose.yml file. You can find it inside the drupal-dockerizer directory.
.
βββ drupal-dockerizer
β βββ runtime-drupal9
β β βββ docker-compose.yml β
β βββ ...
βββ drupal-dockerizer.yml
βββ vendor
β βββ ...
βββ web
βββ index.php
βββ ...cat ~/Projects/drupal9/drupal-dockerizer/drupal9/docker-compose.ymlNow you can use standard Docker Compose to manage your installation.
All the configuration is done via drupal-dockerizer.yml config file. You can find a lot of examples by exploring tests. Take a look at .github/workflows.
Drupal Dockerizer is shipped with additional Ansible playbooks to help you automate your routine tasks. Make sure you are running those playbooks inside the drupal-dockerizer directory. The place where playbook files actually live.
Each new project should start with running up.yml playbook which prepares configuration and up containers. It's an equivalent of docker-compose up command.
To stop your containers and save the data you can use the stop.yml playbook. It's an equivalent of docker-compose stop command.
ansible-playbook stop.ymlTo remove everything and start from scratch you can use clean.yml playbook. This command will not remove your code. Please, note this command requires sudoers permissions.
ansible-playbook clean.yml --ask-become-passAfter resetting your environment you have to run up.yml playbook again to spin up your environment.
Plese, run docker ps to see your Docker container names.
docker exec drupal9-webserver drush statusApache2 and MySQL log files are exposed as volumes, so you can access them by reading the files on your host machine.
cat drupal9/logs/apache2/error.logThere is a playbook which automates database import into database container.
By default it just picks up the dump.sql file from the Drupal root directory.
.
βββ drupal-dockerizer.yml
βββ dump.sql β
βββ ...ansible-playbook db.ymlIf your database dump was placed somewhere in another directory you can change configuration by adding the line to drupal-dockerizer.yml file.
db_dump_path: /path/to/your/dump.sqlThere is drush-commands.yml playbook which will execute all the Drush commands which are described in drupal-dockerizer.yml file. Each new command should go to the new line.
drush_commands:
- cr
- statusDrupal Dockerizer was created and is maintained with β€οΈ by Drupal Dockerizer team and Jet.Dev.