使用容器创建wordpress博客

2020-03-21  本文已影响0人  早_wsm

一、环境准备

下载地址:
链接:https://pan.baidu.com/s/1kZFhC_h2mTDQ5K37z2jzRQ
提取码:8puw

二、部署docker内环境

[root@docker01 ~]#docker pull centos:6.9

[root@docker01 ~]# docker run -it -p 80:80 -p 3306:3306 centos:6.9  /bin/bash

搭建wordpress需要的服务,nginx, mysql, php-fpm,因为要使用nginx与mysql所以做好端口映射80,3306

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo #容器为centos6.9,所以使用6的源

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
在容器内创建存放代码的目录
mkdir /data
上传代码并解压到指定位置
unzip -d /data/ wordpress-5.0.3-zh_CN.zip 
[root@fbd124eb2143 nginx]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /data;  #站点目录
            index  index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           /data; 
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /data$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

检查语法

[root@fbd124eb2143 nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动服务
service nginx start

[root@fbd124eb2143 nginx]# service nginx start
Starting nginx:                                            [  OK  ]
[root@fbd124eb2143 ~]# mysql -uroot
mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
| wordpress          |
+--------------------+
4 rows in set (0.00 sec)

创建并授权用户

mysql> grant all on wordpress.* to wordpress@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

删除无用用户

mysql>  select user,host from mysql.user;
+-----------+--------------+
| user      | host         |
+-----------+--------------+
| wordpress | 10.0.0.%     |
| root      | 127.0.0.1    |
|           | fbd124eb2143 |
| root      | fbd124eb2143 |
|           | localhost    |
| root      | localhost    |
| wordpress | localhost    |
+-----------+--------------+
7 rows in set (0.00 sec)

mysql> drop user ''@'localhost' ;
Query OK, 0 rows affected (0.01 sec)

mysql> drop user ''@'fbd124eb2143' ;
Query OK, 0 rows affected (0.01 sec)
mysql> select user,host from mysql.user;
+-----------+--------------+
| user      | host         |
+-----------+--------------+
| wordpress | 10.0.0.%     |
| root      | 127.0.0.1    |
| root      | fbd124eb2143 |
| root      | localhost    |
| wordpress | localhost    |
+-----------+--------------+
5 rows in set (0.00 sec)

更新一下权限信息

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> Bye
image.png
[root@1c52188827fe wordpress]# rpm -qa|grep -i php
php-fpm-5.3.3-49.el6.x86_64
php-pdo-5.3.3-49.el6.x86_64
php-common-5.3.3-49.el6.x86_64
php-mysql-5.3.3-49.el6.x86_64

service php-fpm restart

image.png
cat /init.sh 
#!/bin/bash

service mysqld start
service php-fpm start
nginx -g 'daemon off;'
[root@docker ~]# docker commit 1c52188827fe centos:6.9_wordpress
sha256:76e675b795f0c3a105fc20aba0c1e04749b678cbfae483fbc55df17c43e54f38
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              6.9_wordpress       76e675b795f0        13 seconds ago      559MB
centos6.9_ssh       v1                  3b3df71e3b73        5 days ago          195MB
nginx               latest              f68d6e55e065        10 days ago         109MB
centos              6.8                 82f3b5f3c58f        3 months ago        195MB
centos              6.9                 2199b8eb8390        3 months ago        195MB

运行刚刚提交的镜像并配合脚本开启

上一篇下一篇

猜你喜欢

热点阅读