Docker部署LNMP环境的WordPress应用
使用Docker 部署LNMP 并搭建wordpress。
- 使用dockerfile构建包含wordpress源文件的nginx+php-fpm镜像;引用了自带php-fpm的nginx镜像
wind@webserver:~$ cat dockerbuild/dockerfile
FROM webdevops/php-nginx:latest
ENV DB_NAME wordpress
ENV DB_USER test
ENV DB_PASSWORD abc123
ENV DB_HOST db
WORKDIR /
RUN curl -o wordpress.tar.gz -SL https://cn.wordpress.org/latest-zh_CN.tar.gz \
&& tar -xvf wordpress.tar.gz \
&& chown -R root:root /app \
&& cp -r wordpress/* /app/ \
&& rm -rf wordpress.tar.gz /wordpress \
&& mkdir /app/wp-content/uploads \
&& chown application:application /app/wp-content/uploads \
&& cp /app/wp-config-sample.php /app/wp-config.php \
&& sed -i s/database_name_here/${DB_NAME}/g /app/wp-config.php \
&& sed -i s/username_here/${DB_USER}/g /app/wp-config.php \
&& sed -i s/password_here/${DB_PASSWORD}/g /app/wp-config.php \
&& sed -i s/localhost/${DB_HOST}/g /app/wp-config.php
- 编写test.yml文件,使用docker-compose –f test.yml up –d 运行
wind@webserver:~$ cat test.yml
version: '3'
services:
nginx:
hostname: web
container_name: web
image: test-web:0.1
ports:
- "80:80"
depends_on:
- mysql
links:
- mysql
mysql:
hostname: db
container_name: db
image: mysql:5.6
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wordpress
MYSQL_USER: test
MYSQL_PASSWORD: abc123