Docker: wordpress dev sandboxed environment

时间:2016-04-15 11:14:01

标签: php mysql wordpress docker

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)?

1 个答案:

答案 0 :(得分:0)

这肯定会有所改进,但这是我采取的步骤:

  1. Install Docker如果尚未完成
  2. 安装Lamp Docker(我宁愿使用nginx而不是apache但是无论如何):docker pull linode/lamp
  3. 运行sudo docker run -p 80:80 -v <local_path_to_site_sources>:/var/www/<sitename> -t -i linode/lamp /bin/bash
  4. 在此步骤中,您已将Docker的端口80转发给您的主机80(这意味着您可以尝试http://localhost并获得结果),并使用包含您的来源的/var/www/<sitename>输入到docker的bash中代码。

    不幸的是还有一些小配置要做,这应该是自动化的恕我直言。

    1. 运行apt-get update(不再是sudo,你是root用户)
    2. 运行apt-get install php5-mysql(由于某些不幸的原因,包裹丢失了)
    3. 通过运行/var/www/<sitename>/log
    4. 确保路径mkdir -p /var/www/<sitename>/log存在
    5. 使用以下内容运行nano /etc/apache2/sites-available/<sitename>.conf(所有内容详细there):

         ServerAdmin网站管理员@#可能不是强制性的    ServerAlias#可能不是强制性的

      #Index文件和文档根目录(公共文件所在的位置)    DirectoryIndex index.html index.php    DocumentRoot / var / www /    #日志文件位置    LogLevel警告    ErrorLog /var/www//log/error.log    CustomLog /var/www//log/access.log结合起来  

    6. 运行a2ensite <sitename>

    7. 无论如何都需要在导入之前创建数据库(可能有办法避免这种情况):mysql -u root -p密码:Admin2015,如[{3}}
    8. 所述
    9. create database <dbname>;然后exit
    10. 中运行
    11. 导入当前数据(如果存在):mysql -u root -p <dbname> < <dbbackupfile>.sql(请注意,<dbbackupfile>.sql需要在泊坞窗中可用,因此输入<local_path_to_site_sources>会有所帮助。

    12. 更新(来自您的主机,而不是泊坞窗,共享文件)wp-config.php

      / ** Nom de la basededonnéesdeWordPress。 * / define('DB_NAME','');

      / **实用主义者基地dedonnéesMySQL。 * / define('DB_USER','root');

      / **基地deDonnéesMyrode passe de la basededonnéesMicrosoft。 * / define('DB_PASSWORD','Admin2015');

      / ** Adresse de l'hébergementMySQL。 * / define('DB_HOST','127.0.0.1');

    13. 运行service apache2 restart; service mysql restart

    14. 去检查here:annnnnndd DONE !!