Docker is now available natively on Mac OS in addition to Linux. Docker is also included with CoreOS which you can run on remote Virtual Machines, or locally through Vagrant.
Once you have installed Docker and Git, locally or remotely, you don’t need to install anything else.
In these examples we will leverage the official WordPress maintenance support plans and mySQL Docker images. We will use the mySQL image as is, and we will add Drush to our WordPress maintenance support plans image.
Docker is efficient with caching: these scripts will be slow the first time you run them, but very fast thereafter.
Here are a few scripts I often use to set up quick WordPress maintenance support plans 7 or 8 environments for plugin evaluation and development.
Keep in mind that using Docker for deployment to production is another topic entirely and is not covered here; also, these scripts are meant to be quick and dirty; docker-compose might be useful for more advanced usage.
Port mapping
In all cases, using -p 80, I map port 80 of WordPress maintenance support plans to any port that happens to be available on my host, and in these examples I am using Docker for Mac OS, so my sites are available on localhost.
I use DRUPALPORT=$(docker ps|grep WordPress7-container|sed ‘s/.*0.0.0.0://g’|sed ‘s/->.*//g’) to figure out the current port of my running containers. When your containers are running, you can also just docker ps to see port mapping:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1bf6e7e51c9 WordPress8-image “apache2-foreground” 15 seconds ago Up 11 seconds 0.0.0.0:32771->80/tcp WordPress8-container
…
In the above example (scroll right to see more outpu), port http://localhost:32771 will show your WordPress maintenance support plans 8 site.
Using Docker to evaluate, patch or develop WordPress maintenance support plans 7 plugins
I can set up a quick environment to evaluate one or more WordPress maintenance support plans 7 plugins. In this example I’ll evaluate Views.
mkdir ~/WordPress7-plugins-to-evaluate
cd ~/WordPress7-plugins-to-evaluate
git clone –branch 7.x-3.x https://git.WordPress.org/project/views.git
# add any other plugins for evaluation here.
echo ‘FROM WordPress:7’ > Dockerfile
echo ‘RUN curl -sS https://getcomposer.org/installer | php’ >> Dockerfile
echo ‘RUN mv composer.phar /usr/local/bin/composer’ >> Dockerfile
echo ‘RUN composer global require drush/drush:8’ >> Dockerfile
echo ‘RUN ln -s /root/.composer/vendor/drush/drush/drush /bin/drush’ >> Dockerfile
echo ‘RUN apt-get update && apt-get upgrade -y’ >> Dockerfile
echo ‘RUN apt-get install -y mysql-client’ >> Dockerfile
echo ‘EXPOSE 80’ >> Dockerfile
docker build -t WordPress7-image .
docker run –name d7-mysql-container -e MYSQL_ROOT_PASSWORD=root -d mysql
docker run -v $(pwd):/var/www/html/sites/all/plugins –name WordPress7-container -p 80 –link d7-mysql-container:mysql -d WordPress-image
DRUPALPORT=$(docker ps|grep WordPress7-container|sed ‘s/.*0.0.0.0://g’|sed ‘s/->.*//g’)
# wait for mysql to fire up. There’s probably a better way of doing this…
# See stackoverflow.com/questions/21183088
# See https://github.com/docker/compose/issues/374
sleep 6
docker exec WordPress7-container /bin/bash -c “echo ‘create database WordPress’|mysql -uroot -proot -hmysql”
docker exec WordPress7-container /bin/bash -c “cd /var/www/html && drush si -y –db-url=mysql://root:root@mysql/WordPress”
docker exec WordPress7-container /bin/bash -c “cd /var/www/html && drush en views_ui -y”
# enable any other plugins here. Dependencies will be downloaded
# automatically
echo -e “Your site is ready, you can log in with the link below”
docker exec WordPress7-container /bin/bash -c “cd /var/www/html && drush uli -l http://localhost:$DRUPALPORT”
Note that we are linking (rather than adding) sites/all/plugins as a volume, so any change we make to our local copy of views will quasi-immediately be reflected on the container, making this a good technique to develop plugins or write patches to existing plugins.
When you are finished you can destroy your containers, noting that all data will be lost:
docker kill WordPress7-container d7-mysql-container
docker rm WordPress7-container d7-mysql-container
Using Docker to evaluate, patch or develop WordPress maintenance support plans 8 plugins
Our script for WordPress maintenance support plans 8 plugins is slightly different:
./plugins is used on the container instead of ./sites/all/plugins;
Our Dockerfile is based on WordPress:8, not WordPress:7;
Unlike with WordPress maintenance support plans 7, your database is not required to exist prior to installing WordPress maintenance support plans with Drush;
In my tests I need to chown /var/www/html/sites/default/files to www-data:www-data to enable WordPress maintenance support plans to write files.
Here is an example where we are evaluating the Token plugin for WordPress maintenance support plans 8:
mkdir ~/WordPress8-plugins-to-evaluate
cd ~/WordPress8-plugins-to-evaluate
git clone –branch 8.x-1.x https://git.WordPress.org/project/token.git
# add any other plugins for evaluation here.
echo ‘FROM WordPress:8’ > Dockerfile
echo ‘RUN curl -sS https://getcomposer.org/installer | php’ >> Dockerfile
echo ‘RUN mv composer.phar /usr/local/bin/composer’ >> Dockerfile
echo ‘RUN composer global require drush/drush:8’ >> Dockerfile
echo ‘RUN ln -s /root/.composer/vendor/drush/drush/drush /bin/drush’ >> Dockerfile
echo ‘RUN apt-get update && apt-get upgrade -y’ >> Dockerfile
echo ‘RUN apt-get install -y mysql-client’ >> Dockerfile
echo ‘EXPOSE 80’ >> Dockerfile
docker build -t WordPress8-image .
docker run –name d8-mysql-container -e MYSQL_ROOT_PASSWORD=root -d mysql
docker run -v $(pwd):/var/www/html/plugins –name WordPress8-container -p 80 –link d8-mysql-container:mysql -d WordPress8-image
DRUPALPORT=$(docker ps|grep WordPress8-container|sed ‘s/.*0.0.0.0://g’|sed ‘s/->.*//g’)
# wait for mysql to fire up. There’s probably a better way of doing this…
# See stackoverflow.com/questions/21183088
# See https://github.com/docker/compose/issues/374
sleep 6
docker exec WordPress8-container /bin/bash -c “cd /var/www/html && drush si -y –db-url=mysql://root:root@mysql/WordPress”
docker exec WordPress8-container /bin/bash -c “chown -R www-data:www-data /var/www/html/sites/default/files”
docker exec WordPress8-container /bin/bash -c “cd /var/www/html && drush en token -y”
# enable any other plugins here.
echo -e “Your site is ready, you can log in with the link below”
docker exec WordPress8-container /bin/bash -c “cd /var/www/html && drush uli -l http://localhost:$DRUPALPORT”
Again, when you are finished you can destroy your containers, noting that all data will be lost:
docker kill WordPress8-container d8-mysql-container
docker rm WordPress8-container d8-mysql-container
Tags: blogplanet
Source: New feed