先上官方文档:
https://docs.docker.com/compose/wordpress/
我的环境:
[root@xyjk1002 ~]# cat /etc/redhat-release
CentOS Linux release 7.2. (Core)
[root@xyjk1002 ~]# uname -r
3.10.-123.9..el7.x86_64
可以使用Docker Compose可以利用容器,在隔离环境下轻松运行WordPress。
1.安装Compose
官方给出的参考文献
https://docs.docker.com/compose/install/
(1)安装docker
文档给出了两种安装方式,但是某些特殊原因,几乎无法下载,最终我们还是选择阿里云的镜像站
地址:
http://mirrors.aliyun.com/help/docker-engine
我使用miyan这个账户安装,首先赋予root权限
[root@xyjk1002 miyan]# visudo
添加这一行
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYoAAABGCAIAAABdQUQ8AAAIXUlEQVR4nO2dO3IbORCG5yj2GSZXufYcU65SrQ+CwMGeYhM4sZJlxBsgVCYlXGWqOcduQM7g1Y3HTIMCxf8rBzKIR+P1EwAxPcP7+/vb29vr6+u/f/85ALCBUZlZTx9tRb+Myhg1frQVNwnkCexh0vM8Q5ySQJ42A3kCAHTK8Xg8HA5PT0+QJwBAX5xOp5eXl+fnZ8gTAKAvIE8AgE7Jy9NysDdp53yPDAQAAEHy8nRRoEm7v8+QgQAAIEhKns4/GnsYpYjAjzAcAPDZya2eRmX0FF7dIAMBAECUjDxdFChSpzgQAABkSchT6dYOEgUAaEF69XQ5+g6PxYlAAAAQJilPFwW6HDWlAgEAQBpcywQAdArkCQDQKZAnAECnQJ4AAJ0CeQIAdMqV5WlUJr4uRQYCQDPpLsYJbiVfgfbyNOlYd8gR1smwcygfgRir16OTcYIuvwLNHapMejYmdJUPeQKb6WScoMuvQGuHKudODOMVytO667uExyMiPVRHZZzncM4RwzzJgmJvDXw1uZhkQYV2uhVdq+jFymRqjVoj0sn9BszMfLsLt80RVHNUxhgzz/OstV6CycA6O21BWlsjrUENG0RrctRNXHdwBxjRUMSpRhYRhypJgZj1FL1qqEiebKL1k1DmMq8wGpWZs3kygZcPtq6e2DyL7OTkadGF8lc32ZhMcte89LeN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b/3+eR+CYHx/Dwia0QarzXdo7E8Je1MVvN/0myRSVCVQ9sAAAAASUVORK5CYII=" alt="" />
OK,将miyan添加到docker用户组,这样就可以不用运行每个docker命令都要加上sudo
[root@xyjk1002 miyan]# usermod -aG docker miyan
OK,切换到miyan用户,安装docker
[miyan@xyjk1002 ~]$ sudo curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh -
启动服务,并设置开机自启动。
[miyan@xyjk1002 ~]$ sudo systemctl start docker.service
[miyan@xyjk1002 ~]$ sudo systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
测试一下:
太慢了,先设置了阿里云docker的加速器。(这一步请去阿里云docker镜像库获取帮助)
[miyan@xyjk1002 ~]$ docker run hello-world Hello from Docker.
This message shows that your installation appears to be working correctly.
OK。
(2)开始安装Compose.
文档提供了三种安装方式,我们采用第一种方式。
curl -L https://github.com/docker/compose/releases/download/1.6.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
无奈,阿里云死活下不下来,直接去github下载最新,并用winscp上传上去。
https://github.com/docker/compose/releases/tag/1.7.0-rc2
下载第二个:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAX0AAACGCAIAAAC+Oc1oAAAPnklEQVR4nO2d72sbRx6H+z/tK2FC6jcJ13AFH+UCub6IQXD48uJexAijGpYEHKe4ByIWQrXPzjmNBCLEELUNSeXEDUowNrbTJGqIcezaL0yNEH4hQZERZe7F7M7OzM6sVrI8kpLPg180q/m5mnn2O7Or7iekdY6Ojo6OjtrICAAAhJBP2sgD7wAATgK8AwAwDbwDADANvAMAMA28AwAwDbwDADANvAMAMA28AwAwDbwDADANvAMAMA28AwAwDbwDADANvAMAMA28AwAwDbwDADANvAMAMA28AwAwDbwDADANvAMAMA28AwAwDbwDADANvAMAMA28AwAwDbwDADBNt7zzYNRSEDlzbmg4Pvt0r36y0jvKq+kvaOu+mH71IdYHgH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z3TwKh38vm8dESpmHw+r76PfgLvqCKU1qdlOO8o6mrJO8KkPYl3pP0dKcLqrHeUcmniHRazyMGm6B1FMqHX3IlSHA9Uhjq9auWoHkKgTYx659atW7ZtZzKZlZWVcrlMOO+Uy+WVlRV6Qz2VSv3xxx+K/J1YZ3kz1re/4wzroJs4Pu+EaGF0qdZ8nRXKOy2us0TkRV+Yu1Sd8Y4z84XvixXubKg3O6VSMp1fnMSHcpeDOyinh3dOHdO/k6C3z3O53MTExOTk5NTU1NTU1OTk5MTERC6X29zcDPyt1mntK0v3MhRFKVwQsoXh9pXDeae1jsvBTpgOiihKkJUdZvO4yZkMKXrFXnKYrjXZ4mmaHuus06Cbvwstl8v091k09gmHNwOjS7uh76Pzw0sKDYTlFcslDEd5CzbAO7q69M1raZ3FlkjiLA13H11ojKaDIif2Di8I/rkHp8FioOHfFwtMFuK5wXAPZwWnh3dOA/x/MPoC/S0nAPoQeKcvgHfABwW80xfAOydAtVr0LzyBSeAdAIBp4B0AgGngHQCAaeAdAIBp4B0AgGngHQCAaeAdAIBp4B0AgGngHQCAaeAdAIBpuuOdIwDARwziHQCAaf4PDsXasmi0QWkAAAAASUVORK5CYII=" alt="" />
[miyan@xyjk1002 ~]$ sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
[miyan@xyjk1002 ~]$ chmod +x /usr/local/bin/docker-compose
[miyan@xyjk1002 ~]$ ll /usr/local/bin/docker-compose
-rwxrwxr-x miyan miyan Apr : /usr/local/bin/docker-compose
验证一下:
[miyan@xyjk1002 ~]$ docker-compose --version
docker-compose version 1.7.0rc2, build ea2d526
OK。
2.Docker-compose文件
(1)创建my_wordpress文件夹,进入该文件夹.编写Dockerfile文件
FROM orchardup/php5
ADD . /code
(2)创建一个docker-compose.yml文件,创建web和mysql
version: ''
services:
web:
build: .
command: php -S 0.0.0.0: -t /code/wordpress/
ports:
- "8000:8000"
depends_on:
- db
volumes:
- .:/code
db:
image: orchardup/mysql
environment:
MYSQL_DATABASE: wordpress
(3)下载wordpress到当前目录
curl https://wordpress.org/latest.tar.gz | tar -xvzf -
(4)在wordpress文件夹中,创建一个wp-config.php的文件,这是wordpress的配置文件,请注意加黑部分,设置显示汉语。
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', "db:3306");
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', ''); define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here'); $table_prefix = 'wp_';
define('WPLANG', ''zh_CN');
define('WP_DEBUG', false); if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/'); require_once(ABSPATH . 'wp-settings.php');
?>
此时,万事具备,我们确认一下,当前文件夹的文件
[miyan@xyjk1002 my_wordpress]$ ls
docker-compose.yml Dockerfile wordpress
3.构建
[miyan@xyjk1002 my_wordpress]$ docker-compose up -d
4.浏览器输入ip:8000
然后就是各类信息填写。
坑:
因为我使用的是https://wordpress.org/latest.tar.gz老外的语言包,即使改了define('WPLANG', ''zh_CN')这,结果还是不能显示汉语。解决办法:
其实,有中文的wordpress,地址:https://cn.wordpress.org/.我们有两种解决办法:
(1)使用中文wordpress包,重新制作镜像。
(2)添加语言文件,把它放到wordpress程序所在目录的“wp-content”目录下即可(把语言文件放在language目录内)。这个语言文件就在中文的wordpress包中。