Ahnii!
This guide could be titled “Docker for Development” and applied to virtually any stack. The examples use Drupal because the scenario involves a Drupal 6 (D6) to Drupal 8 (D8) website migration.
Why Docker for Legacy Development?
The challenge: D6 requires PHP 5.6 or lower, while D8 needs PHP 7.1+. How do you run both PHP versions simultaneously? Instead of managing multiple VMs or complex PHP-FPM setups, Docker provides an elegant solution.
Understanding Containers vs VMs
Virtual Machines
- Full OS and kernel
- Resource heavy
- Slow to start/stop
- Complete isolation
Containers
- Share host kernel
- Lightweight
- Start/stop in milliseconds
- Resource efficient
Setting Up the Environment
First, create the MySQL container:
sudo docker run -d \
--name="drupal-mysql" \
-e MYSQL_ROOT_PASSWORD=drupalroot \
-e MYSQL_DATABASE=drupal6 \
-e MYSQL_USER=drupal \
-e MYSQL_PASSWORD=drupal6pass \
mysql:5.6
Download Drupal 6:
cd ~
wget https://ftp.drupal.org/files/projects/drupal-6.38.tar.gz
tar -xzf drupal-6.38.tar.gz
Create the web container:
sudo docker run -d \
-p 10080:80 \
-v ~/drupal-6.38:/var/www/html \
--name="drupal-app" \
--link="drupal-mysql" \
nimmis/apache-php5
Data Persistence
Docker offers two options for data persistence:
- Volumes (Docker-managed)
- Bind Mounts (host-managed)
For development, bind mounts work well:
-v ~/drupal-6.38:/var/www/html
This mounts the local Drupal directory into the container so file changes persist on the host.
Cleanup
When finished, clean up your containers:
sudo docker container stop drupal-app drupal-mysql
sudo docker container rm drupal-app drupal-mysql
Best Practices
- Use Docker Compose for multi-container setups
- Never store sensitive data in images
- Use .dockerignore files
- Keep images small and focused
Legacy Environments Made Simple
Docker makes it easy to maintain legacy development environments without compromising your host system.
Baamaapii