Dockerfile部署LNMP

【云原生】Dockerfile部署LNMP

文章目录

  • 【云原生】Dockerfile部署LNMP
      • 前言
      • 部署环境
      • 1、安装docker
      • 2、创建Nginx容器
      • 3.创建Mysql容器
      • 4.创建PHP容器
      • 5.测试访问效果

前言

​ 本篇博客为使用Dockerfile搭建LNMP并部署Wordpress

​ 本篇部署基于二进制编译部署

部署环境

部署应用 服务器性能 应用容器网络IP 应用容器名 应用版本
Nginx&Wordpress 2核4G 106.13.0.10 nginx nginx-1.20.1&wordpress-5.8.2
MySQL 2核4G 106.13.0.20 mysql mysql-boost-5.7.20
PHP 2核4G 106.13.0.30 php php-7.1.10

1、安装docker

#1、添加docker-ce的yum源
wget -O /etc/yum.repos.d/docker-ce.repo https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo

#清除rpm包
yum clean all

#重新缓存远端服务器rpm包信息
yum makecache

#2、添加阿里云镜像加速

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ATmLRPN8-1659666381416)(E:\Typora图片保存位置\1.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CmgK95fv-1659666381418)(E:\Typora图片保存位置\2.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NwdfrirN-1659666381418)(E:\Typora图片保存位置\3.png)]

#创建一个目录
mkdir -p /etc/docker 
tree /etc/docker/dacmon.json <<-'EOF'
{
  "registry-mirrors": ["https://g0y3u1zj.mirror.aliyuncs.com"]    #注:这个镜像地址每个人都不一样噢,要看清楚是不是自己的否则无效
}
EOF
#进行重载
systemctl daemon-reload
#3、安装docker
#关闭防火墙
systemctl disable --now firewalld
setenforce 0

#修改网络转发功能(如果不修改,可能造成容器连不上外网,没办法下载环境)
vim /etc/sysctl.conf
	net.ipv4.ip_forward=1
sysctl -p

yum install docker-ce -y

#启动服务并设置开机自启
systemctl start docker
systemctl enable docker

#检查docker是否启动成功
docker info


#docker版本信息
docker version 
[root@docker ~]# docker version 
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:38:53 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       847da18
  Built:            Thu Nov 18 00:37:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
	
#从官网获取centos:7的镜像源
docker pull centos:7

2、创建Nginx容器

mkdir -p /data/nginx
cd /data/nginx
#获取nginx-1.20.1.tar.gz wordpress-5.8.2-zh_CN.tar.gz源码包

nginx官方网址:http://nginx.org/en/download.html
wordpress官方网址:https://cn.wordpress.org/download/releases/

#编写Dockerfile配置文件(尽可能把命令放在一行,减少镜像层数,缩小镜像内存)
vim Dockerfile 
FROM centos:7
MAINTAINER this is nginx images <2952001366@qq.com>
RUN yum install -y pcre-devel zlib-devel gcc gcc-c++ make;useradd -M -s /sbin/nologin nginx
ADD nginx-1.20.1.tar.gz /usr/local/src/
WORKDIR /usr/local/src/nginx-1.20.1
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module;make -j 2 && make install
ENV PATH /usr/local/nginx/sbin:$PATH
ADD nginx.conf /usr/local/nginx/conf/
ADD wordpress-5.8.2-zh_CN.tar.gz /usr/local/nginx/html
RUN chmod 777 -R /usr/local/nginx/html/
EXPOSE 80
VOLUME [ "/usr/local/sbin/nginx/html/" ]
CMD [ "/usr/local/nginx/sbin/nginx","-g","daemon off;" ]

#创建nginx配置文件
vim 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;
        charset utf-8;
        location / {
            root   /usr/local/nginx/html;
            index  index.php index.html;
        }
        location ~ \.php$ {
            fastcgi_pass   106.13.0.30:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

#创建nginx镜像(注意最后有个点,不可省略)
docker build -t nginx:lnmp .
docker images
root@iuwza-an:[2022-07-23 23:10:51]$/data/nginx 
docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        lnmp      9a0f212252f8   2 days ago      612MB
centos       7         eeb6ee3f44bd   10 months ago   204MB

#先自定义一个网络,并定制网段为106.13.0.0/16(网段自己随意更改)
docker network create --driver  bridge --subnet=106.13.0.0/16 --gateway=106.13.0.1 mynet-lnmp


#查看现有的网络模式
docker network ls
root@iuwza-an:[2022-07-23 23:13:38]$/data/nginx 
docker network ls
NETWORK ID     NAME         DRIVER    SCOPE
a17bc80124f7   bridge       bridge    local
d041dcd67efc   host         host      local
1f436cb54593   mynet-lnmp   bridge    local
063368c3a877   none         null      local

##注:查看一下mynet-lnmp网络的详细信息(三个容器的)
root@iuwza-an:[2022-07-24 00:28:00]$/root 
docker network inspect  mynet-lnmp 
[
    {
        "Name": "mynet-lnmp",
        "Id": "1f436cb545931b88d276e9647a5630c8a74f4acba9a4bc23d9be8e755cf54210",
        "Created": "2022-07-21T16:58:40.110091656+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "106.13.0.0/16",
                    "Gateway": "106.13.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "553b28c0b06185c43faa7f88a2a2ebdb87f01e1cc2681c1f0f58447b7010c911": {
                "Name": "php",
                "EndpointID": "9fb13727bbe41143cbcbfb79d427b75128b3eb92f1679e9006d48af31bd07081",
                "MacAddress": "02:42:6a:0d:00:1e",
                "IPv4Address": "106.13.0.30/16",
                "IPv6Address": ""
            },
            "613b90146db60a1bce4adeec2b8604f8cfcf1d02eb6f4685328e0c9769858c2e": {
                "Name": "nginx",
                "EndpointID": "a20e7ffaac3d6b94265c0febde1696ea576843e1e13e76f74f3db0d775e1a96c",
                "MacAddress": "02:42:6a:0d:00:0a",
                "IPv4Address": "106.13.0.10/16",
                "IPv6Address": ""
            },
            "f749710a40d5285cade9b3163b2ee183e3d52854834c7bc238f340065524abc4": {
                "Name": "mysql",
                "EndpointID": "2ae3dc0700736210927c4796b9670a6aa4f73272a311db5602afada3b8bb8669",
                "MacAddress": "02:42:6a:0d:00:14",
                "IPv4Address": "106.13.0.20/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]


#启动nginx容器并且为容器指定IP地址
docker run -d --name nginx -p 80:80 -v /data/nginx/:/usr/local/nginx/conf --net mynet-lnmp --ip 106.13.0.10 nginx:lnmp

#查看是否启动成功
root@iuwza-an:[2022-07-23 23:17:01]$/root 
docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED      STATUS        PORTS                                       NAMES
613b90146db6   nginx:lnmp   "/usr/local/nginx/sb…"   2 days ago   Up 11 hours   0.0.0.0:80->80/tcp, :::80->80/tcp           nginx

#注意/data/nginx下的文件是否有误
root@iuwza-an:[2022-07-23 23:18:04]$/data/nginx 
tree /data/nginx/
/data/nginx/
├── Dockerfile
├── nginx-1.20.1.tar.gz
├── nginx.conf
└── wordpress-5.8.2-zh_CN.tar.gz

#验证nginx容器是否搭建成功
curl localhost:80

root@iuwza-an:[2022-07-23 23:18:16]$/data/nginx 
curl localhost:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

3.创建Mysql容器

#创建mysql目录,并进入目录
mkdir -p /data/mysql && cd /data/mysql
#下载mysql源码包,wget,直接拖入都可

#编写Dockerfile配置文件
vim Dockerfile
FROM centos:7
MAINTAINER this is mysql image <2952001366@qq.com>
RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make;useradd -M -s /sbin/nologin mysql
ADD mysql-boost-5.7.20.tar.gz /usr/local/src/
WORKDIR /usr/local/src/mysql-5.7.20/
RUN cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \  
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \   
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1;make -j 2;make install
ADD my.cnf /etc/my.cnf
EXPOSE 3306
RUN chown -R mysql:mysql /usr/local/mysql/;chown mysql:mysql /etc/my.cnf
WORKDIR /usr/local/mysql/bin/
RUN ./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data;cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/;systemctl enable mysqld
ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
VOLUME [ "/usr/local/mysql" ]
CMD ["/usr/sbin/init"]

#编写mysql配置文件
vim my.cnf
[client]	##代表客户端默认设置内容
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]	##代表数据库自身的默认设置
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

------------------------------
#配置解释
##指定套接字文件的存储路径,数据库连接的文件
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
##承载通讯协议的通讯文件,像登录MySQL时用 -p  ,-u 什么的可以登录,如果没有将会连接不上数据库
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
##指定初始化参数文件目录
-DSYSCONFDIR=/etc \
##指定pid目录文件
-DSYSTEMD_PID_DIR=/usr/local/mysql \
##默认字符集,能识别中文
-DDEFAULT_CHARSET=utf8  \
##安装INNOBASE存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
##安装ARCHIVE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
##安装ARCHIVE存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
##安装FEDERATED存储引擎
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
##字符集扩展更新包,能不断更新字符库
-DDEFAULT_COLLATION=utf8_general_ci \
##数据库里的数据存放的地点
-DMYSQL_DATADIR=/usr/local/mysql/data \

#生成mysql镜像文件并启动镜像容器(需要在对应目录中完成)
docker build -t mysql:lnmp .

#注:在构建mysql镜像的时候出现一个问题
#make编译报错
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.

#因为在编写dockerfile的时候编译是- j 2的多核的编译方法(此前我本身是2核2G的本身环境也在跑其他的脚本内存不足),所以导致编译失败

解决方案:
方法1
直接make,不再使用make -j2等多核编译方法

方法2
使用 swapon -s 查看内存,采用一些方式增加虚拟内存。

#然后我换了个现在2 4 的环境就好了,编译过程很长....

#查看构建的mysql镜像
root@iuwza-an:[2022-07-23 23:16:17]$/data/nginx 
docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
nginx        lnmp      9a0f212252f8   2 days ago      612MB
mysql        lnmp      72e1b36fec44   2 days ago      10GB

#可以看到此时编译的mysql的大小是非常吓人的

#启动mysql镜像
docker run -d  --name=mysql --privileged=true -e MYSQL_ROOT_PASSWORD=an123456 -v data:/usr/local/mysql/data -v base:/usr/local/mysql --net mynet-lnmp --ip 106.13.0.20 mysql:lnmp 

#查看是否成功启动
docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED      STATUS        PORTS                                       NAMES
f749710a40d5   mysql:lnmp   "/usr/sbin/init"         2 days ago   Up 2 days     3306/tcp                                    mysql
613b90146db6   nginx:lnmp   "/usr/local/nginx/sb…"   2 days ago   Up 12 hours   0.0.0.0:80->80/tcp, :::80->80/tcp           nginx

#注意/data/mysql下的文件是否有误
root@iuwza-an:[2022-07-23 23:52:41]$/data/mysql 
tree /data/mysql/
/data/mysql/
├── Dockerfile
├── my.cnf
└── mysql-boost-5.7.20.tar.gz

4.创建PHP容器

#创建php目录并进入
mkdir /data/php && cd /data/php
#下载php包,wget,直接拖入都可
php官方网址:https://www.php.net/releases/
	
#编写Dockerfile
vim Dockerfile
FROM centos:7
MAINTAINER this is php image <2952001366@qq.com>
RUN yum install -y gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel \
gcc gcc-c++ make pcre-devel;useradd -M -s /sbin/nologin nginx
ADD php-7.1.10.tar.gz /usr/local/src/
WORKDIR /usr/local/src/php-7.1.10
RUN ./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip ; make -j 2 ; make install
ENV PATH /usr/local/php/bin:/usr/local/php/sbin:$PATH
ADD php.ini /usr/local/php/lib/
ADD php-fpm.conf /usr/local/php/etc/
ADD www.conf /usr/local/php/etc/php-fpm.d/
EXPOSE 9000
CMD /usr/local/php/sbin/php-fpm -F

#配置php.ini文件
#可以从别的电脑安装配置文件后靠复制过来,只需要修改939行时区,1170行mysql路径指向
	939行:date.timezone = Asia/Shanghai
	1170行:mysqli.default_socket = /usr/local/mysql/mysql.sock
vim php.ini
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 2M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Date]
date.timezone = Asia/Shanghai
[filter]
[iconv]
[intl]
[sqlite3]
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = On
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket = /usr/local/mysql/mysql.sock
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = 1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[opcache]
[curl]
[openssl]

#配置php-fpm.conf文件
vim php-fpm.conf
[global]
pid = run/php-fpm.pid
include=/usr/local/php/etc/php-fpm.d/*.conf

#配置www.conf文件
vim www.conf
[www]
user = nginx
group = nginx
listen = 172.13.0.30:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3


#构建php容器镜像
docker build -t php:lnmp .

#查看构建的php镜像
root@iuwza-an:[2022-07-23 23:59:59]$/data/php 
docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
php          lnmp      5ab5abd752ee   2 days ago      1.27GB
mysql        lnmp      72e1b36fec44   2 days ago      10GB
nginx        lnmp      9a0f212252f8   2 days ago      612MB
centos       7         eeb6ee3f44bd   10 months ago   204MB

#启动php镜像
docker run -d --name php -p 9000:9000 --net mynet-lnmp --ip 106.13.0.30 --volumes-from nginx --volumes-from mysql php:lnmp

#查看是否启动成功
root@iuwza-an:[2022-07-24 00:05:26]$/data/php 
docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED      STATUS        PORTS                                       NAMES
553b28c0b061   php:lnmp     "/bin/sh -c '/usr/lo…"   2 days ago   Up 2 days     0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   php
f749710a40d5   mysql:lnmp   "/usr/sbin/init"         2 days ago   Up 2 days     3306/tcp                                    mysql
613b90146db6   nginx:lnmp   "/usr/local/nginx/sb…"   2 days ago   Up 12 hours   0.0.0.0:80->80/tcp, :::80->80/tcp           nginx

#可以看到三个应用的容器都启动成功了

#进入mysql容器进行授权
#注:进入mysql容器之后进行登录直接回车进入
root@iuwza-an:[2022-07-21 23:49:26]$/data/php 
docker exec -it mysql /bin/bash

[root@f749710a40d5 bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> create database wordpress;	##创建wordpress数据库
Query OK, 1 row affected (0.00 sec)

##进行授权
mysql> grant all privileges on wordpress.* to 'root'@'%' identified by 'an123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'an123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

##修改密码
mysql> alter user root@'localhost' identified by 'an123456';
Query OK, 0 rows affected (0.00 sec)

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

##查看数据库
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

mysql> exit
Bye

##再次进来输入修改之后的面就可以登录了
[root@f749710a40d5 bin]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.20 Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

#注意/data/php下的文件是否有误
root@iuwza-an:[2022-07-24 00:07:49]$/data/php 
tree /data/php/
/data/php/
├── Dockerfile
├── php-7.1.10.tar.gz
├── php-fpm.conf
├── php.ini
└── www.conf

5.测试访问效果

访问:http://ip/wordpress/index.php

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sqSNXBjs-1659666381419)(E:\Typora图片保存位置\wordpress.png)]

#基于dockerfile的源码部署就完成了!
#看看最终通过源码编译形式的三个应用的镜像大小吧
root@iuwza-an:[2022-07-23 23:59:59]$/data/php 
docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
php          lnmp      5ab5abd752ee   2 days ago      1.27GB
mysql        lnmp      72e1b36fec44   2 days ago      10GB
nginx        lnmp      9a0f212252f8   2 days ago      612MB
centos       7         eeb6ee3f44bd   10 months ago   204MB

#可以看到通过源码编译的不管是nginx、mysql、php镜像的大小都是很大的且源码的形式相对麻烦些,

sql>

#注意/data/php下的文件是否有误
root@iuwza-an:[2022-07-24 00:07:49]$/data/php
tree /data/php/
/data/php/
├── Dockerfile
├── php-7.1.10.tar.gz
├── php-fpm.conf
├── php.ini
└── www.conf


### 5.测试访问效果

访问:http://ip/wordpress/index.php



```shell
#基于dockerfile的源码部署就完成了!
#看看最终通过源码编译形式的三个应用的镜像大小吧
root@iuwza-an:[2022-07-23 23:59:59]$/data/php 
docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
php          lnmp      5ab5abd752ee   2 days ago      1.27GB
mysql        lnmp      72e1b36fec44   2 days ago      10GB
nginx        lnmp      9a0f212252f8   2 days ago      612MB
centos       7         eeb6ee3f44bd   10 months ago   204MB

#可以看到通过源码编译的不管是nginx、mysql、php镜像的大小都是很大的且源码的形式相对麻烦些,

你可能感兴趣的:(nginx,运维,服务器,docker)