| Step | docker only | docker compose |
|---|---|---|
| Pull Mysql image | sudo docker pull mysql:5.6 |
? |
| Start 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 |
? |
| Obtain Drupal Code | wget https://ftp.drupal.org/files/projects/drupal-6.38.tar.gz \ tar -xzf drupal-6.38.tar.gz |
|
| Pull Apache image` | $ sudo docker pull nimmis/apache-php5 |
? |
| Build document root container with Apache image and Drupal code | $ sudo docker run -d \ -p 10080:80 \ -v ./drupal-6.38:/var/www/html \ --name="drupal-app" \ --link="drupal-mysql" \ nimmis/apache-php5 |
? |
| Install Drupal interactively in the browser | http://localhost:10080 |
? |
So in Docker for Legacy Drupal Development, using docker only, what happens is this:
drupal-mysql
docker pull mysql:5.6
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.6drupal-app
wget https://ftp.drupal.org/files/projects/drupal-6.38.tar.gz
tar xvzf drupal-6.38.tar.gz
docker pull nimmis/apache-php5
sudo docker run -d \
-p 10080:80 \
-v ~/drupal-6.38:/var/www/html \
--name="drupal-app" \
--link="drupal-mysql" \
nimmis/apache-php5Point browser at http://localhost:10080
Install Drupal interactively.
The container drupal-app is now called d6web and is built in the context of the project root based on Dockerfile, which specifies the nimmis/apache-php5, copies the local project files to the working directory /var/www/html, and exposes port 80. docker-compose.yml
victorkane@Victors-MacBook-Air attempt01 % docker-compose build
d6mysql uses an image, skipping
Building d6web
Step 1/4 : FROM nimmis/apache-php5
---> 2f18ea462e8a
Step 2/4 : WORKDIR /var/www/html
---> Using cache
---> 666366153094
Step 3/4 : COPY ./drupal-6.38/ /var/www/html/
---> 2ca1dab23a03
Step 4/4 : EXPOSE 80
---> Running in 703bb63befc5
Removing intermediate container 703bb63befc5
---> 41be09ed6b04
Successfully built 41be09ed6b04
Successfully tagged d6web:latest
victorkane@Victors-MacBook-Air attempt01 % docker-compose up -d
Creating network "attempt01_d601-network" with driver "bridge"
Creating d6mysql ... done
Creating d6web ... done
victorkane@Victors-MacBook-Air attempt01 % docker exec -it d6web /bin/bash
root@e47b35ee17b4:/var/www/html# ls
CHANGELOG.txt INSTALL.txt UPGRADE.txt install.php robots.txt update.php
COPYRIGHT.txt LICENSE.txt cron.php misc scripts xmlrpc.php
INSTALL.mysql.txt MAINTAINERS.txt includes modules sites
INSTALL.pgsql.txt README.md index.php profiles themes
root@e47b35ee17b4:/var/www/html# exit
exit
victorkane@Victors-MacBook-Air attempt01 % docker-compose down
Stopping d6web ... done
Stopping d6mysql ... done
Removing d6web ... done
Removing d6mysql ... done
Removing network attempt01_d601-networkvictorkane@Victors-MacBook-Air default % ls -l
total 24
-rw-r--r-- 1 victorkane staff 10310 Feb 24 2016 default.settings.php
victorkane@Victors-MacBook-Air default % mkdir files
victorkane@Victors-MacBook-Air default % chmod 777 files
victorkane@Victors-MacBook-Air default % cp default.settings.php settings.php
victorkane@Victors-MacBook-Air default % chmod 666 settings.php
victorkane@Victors-MacBook-Air default % ls -l
total 48
-rw-r--r-- 1 victorkane staff 10310 Feb 24 2016 default.settings.php
drwxrwxrwx 3 victorkane staff 96 Apr 3 11:48 files
-rw-rw-rw- 1 victorkane staff 10310 Apr 3 12:18 settings.php
docker build
docker up -d
docker-machine ip default
192.168.99.101browse to: http://192.168.99.101:10080
in interactive install, cite mysql host and port in advanced settings as follows: d6mysql and 3306 (shouldn't require port but seems to need it)
Creating network "attempt01_d601-network" with driver "bridge"
Creating d6mysql ... done
Creating d6web ... done
victorkane@Victors-MacBook-Air attempt01 % docker-compose down -v --rmi all
Stopping d6web ... done
Stopping d6mysql ... done
Removing d6web ... done
Removing d6mysql ... done
Removing network attempt01_d601-network
Removing image mysql:5.6
Removing image d6web
Adjust the directory drupal-6.38/sites/default/ as follows:
% docker-compose down
Stopping d6web ... done
Stopping d6mysql ... done
Removing d6web ... done
Removing d6mysql ... done
Removing network attempt01_d601-network
% ls -l drupal-6.38/sites/default
total 48
-rw-r--r-- 1 victorkane staff 10310 Feb 24 2016 default.settings.php
drwxrwxrwx 3 victorkane staff 96 Apr 3 11:48 files
-rw-rw-rw- 1 victorkane staff 10310 Apr 3 14:36 settings.php
% diff drupal-6.38/sites/default/default.settings.php drupal-6.38/sites/default/settings.php
%Just a few lines in the docker-compose.yml file:
...
d6mysql:
...
volumes:
- db_d601_data:/var/lib/mysql
...
volumes:
db_d601_data:root@137949ae85b4:/# mysqldump -u drupal601 -p drupal601 > db.sq
root@137949ae85b4:/# head -20 db.sql
-- MySQL dump 10.13 Distrib 5.6.47, for Linux (x86_64)
--
-- Host: localhost Database: drupal601
-- ------------------------------------------------------
-- Server version 5.6.47
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `access`
--
root@137949ae85b4:/# exit
docker cp d6mysql:/db.sql backup
% ls -l backup
total 1496
-rw-r--r-- 1 victorkane staff 762908 Apr 3 16:27 db.sqlFirst down the app, removing images but not volumes. Then build, come back up, check to make sure site still up with content and admin login.
% docker-compose down --rmi all
Stopping d6web ... done
Stopping d6mysql ... done
Removing d6web ... done
Removing d6mysql ... done
Removing network attempt01_d601-network
Removing image mysql:5.6
Removing image d6web
victorkane@Victors-MacBook-Air attempt01 % grep mysql drupal-6.38/sites/default/settings.php
* $db_url = 'mysql://username:password@localhost/databasename';
* $db_url = 'mysqli://username:password@localhost/databasename';
$db_url = 'mysqli://drupal601:drupal601p@d6mysql:3306/drupal601';
% docker-compose build
d6mysql uses an image, skipping
Building d6web
Step 1/4 : FROM nimmis/apache-php5
---> 2f18ea462e8a
Step 2/4 : WORKDIR /var/www/html
---> Using cache
---> 666366153094
Step 3/4 : COPY ./drupal-6.38/ /var/www/html/
---> de1a2b3fae81
Step 4/4 : EXPOSE 80
---> Running in 9a4123d55eb1
Removing intermediate container 9a4123d55eb1
---> f50053ad862d
Successfully built f50053ad862d
Successfully tagged d6web:latest
% docker-compose up -d
Creating network "attempt01_d601-network" with driver "bridge"
Pulling d6mysql (mysql:5.6)...
5.6: Pulling from library/mysql
48839397421a: Pull complete
725652de4539: Pull complete
e4e83fcf33af: Pull complete
d22eed95a35d: Pull complete
7c6413e9e73a: Pull complete
db37ee61b2cc: Pull complete
5f352f2d0e1b: Pull complete
6f664886aa54: Pull complete
7f4961f446cc: Pull complete
7e610963b475: Pull complete
2b007da11435: Pull complete
Digest: sha256:f0165a6f800d183ca92ab822e2fe6157acebc5752bab3ca2b9e805b2fa894bc8
Status: Downloaded newer image for mysql:5.6
Creating d6mysql ... done
Creating d6web ... doneIndeed, everything comes up, reload page, logout, login, check content, story and page still there.
a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
root@602acc2b32d7:/var/www/html# service apache2 restart
* Restarting web server apache2
cat /etc/apache2/sites-available/ 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory "/var/www/html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost *:80>Then enable at http://192.168.99.101:10080/?q=admin/settings/clean-urls (assuming clean url test passes and the enable option is not disabled)
This hard-coded config plus of course db config (persisted in volume) survives stop/start but not down (container destroyed without committing changes to new image)
% docker-compose stop
% docker-compose start
TODO create image that manages this with command in original image creation (build/up)
- Create top-level db-backups directory
- .keep file
- gitignore common backup files ()
- Small & medium
- backup database
% docker exec d6mysql which mysqldump
/usr/bin/mysqldump
% docker exec -it d6mysql /usr/bin/mysqldump -u drupal601 -p drupal601 > ./db-backups/202004041426-db.sql
victorkane@Victors-MacBook-Air attempt01 % ls -l db-backups
total 9704
-rw-r--r-- 1 victorkane staff 1187055 Apr 4 14:26 202004041426-db.sqlSo we'll stop our container set and delete the containers and images (all, but without killing the database volume. Then we'll make these changes, build and bring up again.
docker-compose down --rmi all
docker-compose build
docker-compose up -dBut we if we're only making dev changes to d6web, we could just do:
docker-compose down
docker rmi d6web
docker-compose build
docker-compose up -d- Move from project root to
.dockersubdir with its own name - Add clean urls to the image
Done! With help from socketwench / drupal-base. Our commit: feat(docker image d6web): Add clean urls to the image
We can add drush 8. See drush installation docs
Now, how to implement this? With a separate drush image? Including drush with the d6web image, where it will have to work anyway? Including it with the mysql image? There's more than one way to do it: How to use docker with drupal and drush?. Maybe the coolest way is to have a separate docker container running drush and volume share not only the drupal file system but also the mysql client executable... Oh my! Interesting discussion here too: RobLoach/drush-docker#32. And here: Ride the Whale presentation.
So after entertaining myself with these options for some time, and doing a lot of stuff like docker rm $(docker ps -a --filter "name=attempt01*" -q), I decided that for our purposes (run migration scripts), we can simply install composer, drush and the mysql client only on the drupal web container d6web.
TODO: Commit:
% docker exec d6web drush status
victorkane@Victors-MacBook-Air attempt01 % docker exec d6web drush status
Drupal version : 6.38
Site URI : http://default
Database driver : mysql
Database hostname : d6mysql
Database port : 3306
Database username : drupal601
Database name : drupal601
Database : Connected
Drupal bootstrap : Successful
Drupal user :
Default theme : garland
Administration theme : garland
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush script : /.composer/vendor/drush/drush/drush.php
Drush version : 8.3.2
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Install profile : default
Drupal root : /var/www/html
Drupal Settings File : sites/default/settings.php
Site path : sites/default
File directory path : sites/default/files
Temporary file directory path : /tmp
% docker exec d6web drush user-information admin
User ID : 1
User name : admin
User mail : admin@durabledrupal.net
User roles : authenticated user
User status : active
% docker exec d6web drush pm-list | grep Enabled
Core - optional Color (color) Module Enabled 6.38
Core - optional Comment (comment) Module Enabled 6.38
Core - optional Database logging (dblog) Module Enabled 6.38
Core - optional Help (help) Module Enabled 6.38
Core - optional Menu (menu) Module Enabled 6.38
Core - optional Taxonomy (taxonomy) Module Enabled 6.38
Core - optional Update status (update) Module Enabled 6.38
Core - required Block (block) Module Enabled 6.38
Core - required Filter (filter) Module Enabled 6.38
Core - required Node (node) Module Enabled 6.38
Core - required System (system) Module Enabled 6.38
Core - required User (user) Module Enabled 6.38
Other Garland (garland) Theme Enabled 6.38
% docker exec -it d6web /bin/bash
root@bf97bf0c8dc0:/var/www/html# drush sql-query "select * from node"
1 1 page New times a bordin 1 1 1585940332 1585940332 0 0 0 0 0 0
2 2 story Welcome to DD D6 DC 1 1 1585940381 1585944447 0 1 0 0 0 0
3 3 page Virus 1 1 1585944408 1585944408 0 0 0 0 0 0
docker exec -i d6web drush sql-dump | less
-- MySQL dump 10.13 Distrib 5.5.62, for debian-linux-gnu (x86_64)
--
-- Host: d6mysql Database: drupal601
-- ------------------------------------------------------
-- Server version 5.6.47
victorkane@Victors-MacBook-Air attempt01 % docker exec d6web chmod +x scripts/dd-get-users.php
victorkane@Victors-MacBook-Air attempt01 % docker exec d6web ls -l scripts/dd-get-users.php
-rwxr-xr-x 1 1000 staff 162 Apr 5 10:38 scripts/dd-get-users.php
victorkane@Victors-MacBook-Air attempt01 % docker exec d6web cat scripts/dd-get-users.php
#!/usr/local/bin/drush
$result = db_query('SELECT uid FROM users');
while ($obj = db_fetch_object($result)) {
$user = user_load($obj->uid);
print_r($user);
}% victorkane@Victors-MacBook-Air attempt01 % docker exec d6web scripts/dd-get-users.php
stdClass Object
(
[uid] => 2
[name] => victorkane
[pass] => dd070b0bbcb6b8b496e08dada7e01866
[mail] => victorkane@dd.com
[mode] => 0
[sort] => 0
[threshold] => 0
[theme] =>
[signature] =>
[signature_format] => 0
[created] => 1585944341
[access] => 0
[login] => 0
[status] => 1
[timezone] => -10800
[language] =>
[picture] =>
[init] => victorkane@dd.com
[data] => a:1:{s:13:"form_build_id";s:48:"form-Rhxnj7VQO5TmRzJBNPM3gNPBh_QqkbxB9RiHvWKe8ns";}
[form_build_id] => form-Rhxnj7VQO5TmRzJBNPM3gNPBh_QqkbxB9RiHvWKe8ns
[roles] => Array
(
[2] => authenticated user
)
)
...
- Docker for Legacy Drupal Development
- Dockerize an Existing Project | Drupalize.Me
- Quickstart: Compose and WordPress
- docker hub for image nimmis/apache-php5
- docker hub for official image mysql
- Mysql Installation Guide. Basic Steps for MySQL Server Deployment with Docker
- docker4drupal
- drush
- etc