#创建wordpress目录并进入
mkdir wordpress
cd wordpress
wordpress目录下需要的东西
docker-entrypoint.sh脚本是为了在Dockerfile中CMD执行,启动nginx和php
chmod 777 -R /usr/share/nginx/wordpress
nginx && \
/opt/remi/php80/root/usr/sbin/php-fpm
if [ $? -eq 0 ];then
echo "nginx和php启动成功"
fi
tailf /var/log/nginx/*
latest-zh_CN.tar.gz这个是wordpress包,直接下载,不用解压,但是要放在wordpress目录下
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
nginx.conf文件是替换容器内的此文件
如果嫌麻烦的话,可以直接创建nginx.conf文件然后复制下面代码
还可以在命令行下载nginx将其配置文件拷贝过来。但是需要更改网站发布目录
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/wordpress;
index index.php;
}
location ~ \.php$ {
root /usr/share/nginx/wordpress; #指定网站目录
fastcgi_pass 127.0.0.1:9000; #指定访问地址
fastcgi_index index.php; #指定默认文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #站点根目录,取决于root配置项
include fastcgi_params; #包含nginx常量定义
}
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
Dockerfile部署
FROM centos:7.9.2009
LABEL name="shisan"
RUN yum -y install epel-release && \
yum -y install nginx && \
yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm && \
yum install -y php80-php-xsl php80-php php80-php-cli php80-php-devel php80-php-gd php80-php-pdo php80-php-mysql php80-php-fpm && \
yum clean all
COPY ./nginx.conf /etc/nginx
COPY ./docker-entrypoint.sh /
ADD ./latest-zh_CN.tar.gz /usr/share/nginx
CMD [ "sh","/docker-entrypoint.sh" ]
直接build,注意命令写法,后面有个点,不是表示本目录,表示上下文关系。构建时间比较长,耐心等待
docker build -t wordpress:v1.0 .
运行构建好的wordpress镜像
docker run -it wordpress:v1.0
启动后夯住,会提醒nginx和php已启动
然后直接IP在浏览器访问
这个时候需要将数据库导进来
docker run -itd --name mysql.server -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress daocloud.io/library/mysql:5.7
#密码就是设置的密码,123456
然后就随便操作了