Docker:wordpress dev沙盒环境

I don't work with WP neither PHP. But sometimes I'm asked to have a look at a wordpress site (we've all been through this ... sight)

Instead of installing LAMP or whatever, I'd rather sandbox the shit in a docker, so I can easily uninstall everything once done.

I find the docker-compose approach as suggested in the official wordpress docker kind of complicated.

Instead, since it is for development purpose only, I'd rather have a single Docker that would contain the whole PHP + MySQL config, and simply having to:

  1. Replace DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php

  2. Import the SQL of the existing DB. Eg. docker run mydocker /bin/mysql-import ~/Desktop/export.sql

  3. docker start mydocker --source ~/Workspace/myproject

Does this approach make sense? Are there any ressource I could find to achieve this (if it hasn't been done already)?

This shall certainly be improved, but here are the steps I took:

  1. Install Docker if not already done
  2. Install the Lamp Docker (I'd have rather used nginx instead of apache but anyways): docker pull linode/lamp
  3. Run sudo docker run -p 80:80 -v <local_path_to_site_sources>:/var/www/<sitename> -t -i linode/lamp /bin/bash

At this step, you have forwarded Docker's port 80 to your host 80 (which means you can try out http://localhost and should get a result), entered into the docker's bash with /var/www/<sitename> containing your source code.

Unfortunately there is still some little config to make, which should be automated IMHO.

  1. Run apt-get update (no more sudo, you are root there)
  2. Run apt-get install php5-mysql (for some unfortunate reason, the package was missing)
  3. Make sure the path /var/www/<sitename>/log exists by running mkdir -p /var/www/<sitename>/log
  4. Run nano /etc/apache2/sites-available/<sitename>.conf with the following content (everything's detailed there):

    ServerAdmin webmaster@ # Probably not mandatory ServerAlias # Probably not mandatory

    # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /var/www/ # Log file locations LogLevel warn ErrorLog /var/www//log/error.log CustomLog /var/www//log/access.log combined

  5. Run a2ensite <sitename>

  6. The database needs to be created before being imported anyways (maybe there a way to avoid this): mysql -u root -p password: Admin2015 as explained here
  7. Run in-there create database <dbname>; then exit
  8. Import current data if exists: mysql -u root -p <dbname> < <dbbackupfile>.sql (note that the <dbbackupfile>.sql needs to be available in the docker, so putting in into your <local_path_to_site_sources> shall help.

  9. Update (from your host, not the docker, the files are shared) wp-config.php with:

    /** Nom de la base de données de WordPress. */ define('DB_NAME', '');

    /** Utilisateur de la base de données MySQL. */ define('DB_USER', 'root');

    /** Mot de passe de la base de données MySQL. */ define('DB_PASSWORD', 'Admin2015');

    /** Adresse de l'hébergement MySQL. */ define('DB_HOST', '127.0.0.1');

  10. Run service apache2 restart; service mysql restart

  11. Go check http://localhost : annnnnndd DONE!!