Docker容器与虚拟化技术:Dockerfile部署LNMP

news/2024/11/17 20:50:25/

目录

一、理论

1.LNMP架构

2.背景

3.Dockerfile部署LNMP

3.构建Nginx镜像

4.构建MySQL容器

5.构建PHP镜像

6.启动 wordpress 服务 

二、实验

 1.环境准备

2.构建Nginx镜像

3.构建MySQL容器

4.构建PHP镜像

5.启动 wordpress 服务 

三、问题

1.构建nginx镜像报错

2.构建php镜像报错

2.生成PHP镜像一直为Exited状态

3.wordpress页面无法跳转

4.如何将运行中的 docker容器保存为 docker 镜像并保存到本地tar包

 四、总结


 

 

 

 

一、理论

1.LNMP架构

(1)架构

搭建一个lnmp环境,需要涉及到两个目录结构。一个是Dockerfile配置的目录结构,另一个是最终lnmp运行的目录结构。Dockerfile配置目录主要存放Dockerfile构建脚本和一些配置文件,lnmp运行目录主要存放程序运行产生的一些数据,比如mysql数据等。
以下是此次Dockerfile配置的目录结构,包括了nginx、php、mysql的配置文件。
 

lnmp- nginx- Dockerfile- nginx.conf- sites-enabled- default.conf...- php- Dockerfile- php.ini- php-fpm.conf- www.conf- mysql- Dockerfile- mysqld.cnf

 

c414107f773143858b2172a51a9f3e6b.png

 

2.背景

(1)项目环境

公司在实际的生产环境中,需要使用 Docker 技术在一台主机上创建 LNMP 服务并运行 Wordpress 网站平台。然后对此服务进行相关的性能调优和管理工作。

(2)所有安装包下载

nginx:

nginx:下载

MySQL:

MySQL :: MySQL 下载

PHP:

PHP: 下载

 

(3)任务需求
使用 Docker 构建 LNMP 环境并运行 Wordpress 网站平台
限制 Nginx 容器最多使用 500MB 的内存和 1G 的 Swap
限制 Mysql 容器写 /dev/sda 的速率为 10 MB/s
将所有容器进行快照,然后将 Docker 镜像打包成 tar 包备份到本地

 

3.Dockerfile部署LNMP

(1)关闭防火墙

systemctl stop firewalld 
systemctl disable firewalld
setenforce 0

先自定义网络,再使用指定IP运行docker

是LNMP各组件处于同一网段

docker network create --subnet=172.20.0.0/16 --opt "com.docker.network.bridge.name"="docker1" mynetwork

Docker各组件的ip为:

容器操作系统IP地址主要软件
nginxCentOS 7172.20.0.10Docker-Nginx
mysqlCentOS 7172.20.0.20Docker-Mysql
phpCentOS 7172.20.0.30Docker-php
 

 

 此实验所需的软件有:

mysql-boost-5.7.20.tar.gz
nginx-1.12.0.tar.gz
php-7.1.10.tar.bz2
wordpress-4.9.4-zh_CN.tar.gz

检测网络:

[root@localhost nginx]# docker network ls
NETWORK ID     NAME        DRIVER    SCOPE
67e4b5a96733   bridge      bridge    local
f0c0eb06bea1   host        host      local
74f81b65c02c   mynetwork   bridge    local
f20ccdc6d825   none        null      local
[root@localhost nginx]# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255inet6 fe80::42:58ff:fe04:a8bd  prefixlen 64  scopeid 0x20<link>ether 02:42:58:04:a8:bd  txqueuelen 0  (Ethernet)RX packets 15632  bytes 631663 (616.8 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 23932  bytes 92428320 (88.1 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0docker1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 172.20.0.1  netmask 255.255.0.0  broadcast 172.20.255.255inet6 fe80::42:47ff:fe2b:be52  prefixlen 64  scopeid 0x20<link>ether 02:42:47:2b:be:52  txqueuelen 0  (Ethernet)RX packets 7  bytes 1189 (1.1 KiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 22  bytes 2393 (2.3 KiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

3.构建Nginx镜像

(1) 创建nginx的工作目录

mkdir /opt/nginx
cd /opt/nginx/

(2) 上传 nginx-1.12.0.tar.gz、wordpress-4.9.4-zh_CN.tar.gz 到 /opt/nginx/ 目录中

[root@localhost nginx]# rz -E
rz waiting to receive.
[root@localhost nginx]# ls
Dockerfile  nginx-1.12.0.tar.gz  nginx.conf  run.sh  wordpress-4.9.4-zh_CN.tar.gz

(3)编辑Dockerfile配置文件

vim Dockerfile
FROM centos:7
MAINTAINER this is nginx image <lnmp>
RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make;useradd -M -s /sbin/nologin nginx
ADD nginx-1.12.0.tar.gz /usr/local/src/
WORKDIR /usr/local/src/nginx-1.12.0
RUN ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module;make -j 4 && make install
ENV PATH /usr/local/nginx/sbin:$PATH
ADD nginx.conf /usr/local/nginx/conf/
ADD wordpress-4.9.4-zh_CN.tar.gz /usr/local/nginx/html
RUN chmod 777 -R /usr/local/nginx/html/
EXPOSE 80
VOLUME [ "/usr/local/nginx/html/" ]
CMD [ "/usr/local/nginx/sbin/nginx","-g","daemon off;" ]

(4) 准备Dockerfile文件中所需要的其他配置文件

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   html;index  index.html index.php;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location ~ \.php$ {root           html;fastcgi_pass   172.20.0.30:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;include        fastcgi_params;}}
}

(5) 构建nginx镜像

docker build -t nginx:lnmp .

(6) 启动Nginx容器

docker run -d --name nginx -p 80:80 -m 500m --memory-swap 1g --net mynetwork --ip 172.20.0.10 nginx:lnmp

(7)查看

docker inspect nginx"Networks": {"mynetwork": {"IPAMConfig": {"IPv4Address": "172.20.0.10"

(8)验证nginx

curl http://192.168.204.140:80

 

4.构建MySQL容器

(1) 创建MySQL工作目录

mkdir /opt/mysqld
cd /opt/mysqld

(2) 上传 mysql-boost-5.7.20.tar.gz 到 /opt/mysqld 目录中

[root@localhost mysql]# rz -E
rz waiting to receive.
[root@localhost mysql]# ls
mysql-boost-5.7.20.tar.gz

(3) 编辑Dockerfile文件

 vim Dockerfile 
FROM centos:7
MAINTAINER this is mysql image <lnmp>
RUN yum -y install ncurses ncurses-devel bison cmake pcre-devel zlib-devel gcc gcc-c++ 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 -j4;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"]

(4)编辑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 = 1sql_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

(5)编辑MySQL的启动脚本

vim run.sh#!/bin/bash
/usr/local/mysql/bin/mysqld
systemctl enable mysqld

(6)构建MySQL镜像

docker build -t mysql:lnmp .

(7)启动MySQL镜像

docker run --name=mysql -d --privileged --device-write-bps /dev/sda:10M -v /usr/local/mysql --net mynetwork --ip 172.20.0.20 mysql:lnmp

(8)验证 mysql 

[root@localhost mysql]# docker exec -it mysql bash
[root@75e85cb863da bin]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)Active: activating (start) since Fri 2023-08-18 06:15:20 UTC; 1min 54s agoDocs: man:mysqld(8)http://dev.mysql.com/doc/refman/en/using-systemd.htmlProcess: 99 ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)Process: 80 ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)CGroup: /docker/75e85cb863da16ddb6d557159d0a946fc2841da58683486ec8781464bbf19a8d/system.slice/mysqld.service└─101 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/my...

 

5.构建PHP镜像

(1) 创建工作目录

mkdir /opt/php
cd /opt/php

(2)上传 php-7.1.10.tar.bz2 到 /opt/php 目录中

[root@localhost php]# ls
[root@localhost php]# rz -E
rz waiting to receive.
[root@localhost php]# ls
php-7.1.10.tar.bz2  php-fpm.conf  php.ini  www.conf

(3)编辑Dockerfile文件

vim Dockerfile 
FROM centos:7
MAINTAINER this is php image <lnmp>
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.bz2 /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 4 ; 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

(4)准备Dockerfile需要的PHP配置文件

①配置php.ini文件

vim php.ini
#939行,取消注释,修改
date.timezone = Asia/Shanghai
#1170行,修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
[root@benet23 php]# egrep -v "^;" php.ini | egrep -v "^$"
[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 
#17行,删除注释符号“;”
pid = run/php-fpm.pid
[root@docker php]# egrep -v "^;" php-fpm.conf | egrep -v "^$"
[global]
pid = run/php-fpm.pid
include=/usr/local/php/etc/php-fpm.d/*.conf

③配置www.conf文件

vim www.conf 
#23、24行,修改用户和组
user = nginx
group = nginx
#36行,修改监听IP和端口为容器IP:9000端口
listen = 172.20.0.30:9000
[root@docker php]# egrep -v "^;" www.conf | egrep -v "^$"
[www]
user = nginx
group = nginx
listen = 172.20.0.30:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

(5)构建php镜像

docker build -t php:lnmp .

(6)启动PHP镜像

注意:此时MySQL容器要处于运行的状态

docker run -itd --name php --net mynetwork --ip 172.20.0.30 -p 9000:9000 --volumes-from nginx --volumes-from mysql php:lnmp

 

(7) 验证php

①进入php容器

[root@localhost php]# docker exec -it php bash
[root@12a35bf91472 php-7.1.10]# ps -aux
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root          1  0.0  0.0 113028  7520 pts/0    Ss+  07:01   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nginx         7  0.0  0.0 113028  3772 pts/0    S+   07:01   0:00 php-fpm: pool www
nginx         8  0.0  0.0 113028  3772 pts/0    S+   07:01   0:00 php-fpm: pool www
root          9  0.6  0.0  11828  1892 pts/1    Ss   07:02   0:00 bash
root         23  0.0  0.0  51732  1724 pts/1    R+   07:02   0:00 ps -aux

 

6.启动 wordpress 服务 

(1) mysql 授权
进入 mysql 容器

[root@75e85cb863da bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20 Source distributionCopyright (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> create database wordpress;
Query OK, 1 row affected (0.01 sec)mysql> grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql> 

浏览器访问:

部署

http://192.168.204.140/wordpress/wp-admin/setup-config.php

 

 

 

二、实验

 1.环境准备

(1)关闭防火墙

8093566fb0054bc0b4497c074910e2a0.png

先自定义网络,再使用指定IP运行docker

是LNMP各组件处于同一网段

 84870b85ad0d48b4b49d4ad73b2a5128.png4abbcf5f378a4077bbf1c7195a2ba48d.png

 

10ce9d5a683642faaee0e95365a45a66.png

 

 

Docker各组件的ip为:

2799b2537bf4487a981cedbe58d7d8af.png

 

 

2.构建Nginx镜像

(1) 创建nginx的工作目录

b4ce2f7cd73049809bf7f8e47b2251d8.png

a800a3339e8e498d92598630f6d59ad6.png

(2) 上传 软件包到 /opt/nginx/ 目录中

 9ad94dabef2146419106b1e75989458e.png

 

(3)编辑Dockerfile配置文件b871824a87944dba8e3bb957242b730e.png

00bb155ea1c741d4b606b2443fce6bd2.png

 

(4) 准备Dockerfile文件中所需要的其他配置文件

94c8cc6070b3449fa4dffa3202222299.png

 

取消注释,指定PHP网页文件、指定IP和端口号

afd6543046c34652ac159443c71941a1.png

 

(5) 构建nginx镜像b05b6fae903c45b7943142bd05a57710.png

 

(6) 启动Nginx容器

c19055e4613f4e4f86f3f236bb40182f.png

 (7)查看 

b7ffb86a9fda41ee9c4b4fb4d372b49f.png

 33a545b92a76402d919e868e54ba7707.png95ed849d439a4d5aa307a596d31e8a02.png

 (8)验证 nginx 6bbae1d41816445185a09e667c373cf5.png

 cc88cc82d8dd4b389bec8b409391c2fe.png

 

 

3.构建MySQL容器

(1) 创建MySQL工作目录

 

0a9384548cc84f6da2c3ee2eb6f47329.png

(2) 上传 mysql-boost-5.7.20.tar.gz 到 /opt/mysqld 目录中e797ecb9301947cd87341de85b972f97.png

 

 

(3) 编辑Dockerfile文件

479781fafc0644868cb7c577fe639b9b.png2a4562f3f119440da61ad8719085b3ef.png

 

(4)编辑mysql的配置文件

bbe493eba6e743f6a611080f8e93447d.png

 

4ed3a555181e4aca9f098cd3c4d666f3.png

(5)构建MySQL镜像b16b6a6bcfe243bb8fc84112ff35a9b2.png

7ed3b44f07b94b0bbe64506193ccfd47.png

 

(6)启动MySQL镜像2be2d203e3f444a29be25e7493818c47.png4635656adf70459db3a83c0c66367ad6.png

 

 

 

(7)验证 mysql 

9f98354434014ef5967fb58aab8418dc.png

 

 

4.构建PHP镜像

(1) 创建工作目录dc074d3a3989453691e2b2e8d5f233c0.png

 

(2)上传 php-7.1.10.tar.bz2 到 /opt/php 目录中

868e06bb28164aa3a2ce163f9bc1cce9.png

 

(3)编辑Dockerfile文件

3e6a0cec34024343bb6d73c9f9b2d488.png

23cb3c92d3ca4b1eb832e03f16d14b01.png

 

 

(4)准备Dockerfile需要的PHP配置文件

f61794f788154569a56212e8aac53ca0.png

 

(5)构建php镜像2134d429d65147909b9b120764b5f8a8.png

 ​​​​​​​84747a4e1b90483897ed8ab1187674a3.png

 

(6)启动PHP镜像

注意:此时MySQL容器要处于运行的状态

 

76b53dbdb1234057b7912cba86653d52.png

 查看,php镜像启动成功

 

5b394bd5b61b4d3eb975fa750dfb4d55.png

 

(7) 验证php

406679f3a82a4cafb4c5076522e430cc.png

 

 

5.启动 wordpress 服务 

(1)mysql 授权

进入mysql容器,登录数据库​​​​​​​b05171e99e6148f9be2ced1badaefe5d.png

 

(2) 浏览器访问测试

http://192.168.204.140/wordpress/wp-admin/setup-config.php

进入配置页面

80719d856cf84a9fb1a39329759de9a5.png

 输入用户名和密码

a17c8bacf88d422aa43f9a671149a2cc.png

 现在安装

886da657e0664479aa99b65005be439e.png

 设置用户名和密码

bc143e32b337423cbacd826539301ae2.png

 

点击 登录

336fb12ea4a24a2f865c88347b3c0544.png

 登录成功b3bd59a0ad9d4af582b8b2a637f244ce.png

 进入系统

http://192.168.204.140/wordpress/wp-admin/

28959645705f4e479ae3be95ea394f4f.png

 首页展示

707ebab15eda4e1d8cdd19675ed84756.png

 

 

三、问题

1.构建nginx镜像报错

(1)报错

b8d02f85338c40e9b588671e56e8480a.png

 (2)原因分析

存放的wordpress版本错误

(3)解决方法

重新上传(正确的为4.9.4)

0f6c616c15724c00bd7b8d91c2ffc7c2.png

 

2.构建php镜像报错

(1)报错

af2ef1f737ea477a99d2295828c57bb9.png

 

 (2)原因分析

存放的php版本错误

(3)解决方法

重新上传(正确的为bz2)

0fd0d226f5084d318d9a34035c5f70fc.png

 

2.生成PHP镜像一直为Exited状态

(1)报错

PHP镜像一直为Exited状态

a6c47a26a19c41a6a3db5bd5a412c505.png

查看日志

f0202701289c4313b0ba5165de1618be.png

 (2)原因分析

无法监听正确地址,需要修改监听地址

(3)修改配置文件​​​​​​​

 

aafff43c8aa0449f9ebc4904ee2c42ff.png

6338bdc39cc548028bd2eff7e5015bd6.png

 

3.wordpress页面无法跳转

(1)报错

访问页面无法跳转wordoress

a4b1ee63f3334a32bc910638ec1964da.png

 

(2)原因分析

56f40bbebf7840008b38a9ce867605be.png

 nginx配置文件反向代理地址填写错误,需要修改

(3)修改

0d6e0209aabc447bbd884f047715cbd8.png

a4ef283af28b419e864e2f772d970d0a.png

 

4.如何将运行中的 docker容器保存为 docker 镜像并保存到本地tar包

(1)方法

1、docker commit <容器id> <镜像名>:<tag>     ---- 将容器保存成镜像,tag比如说latest保存后 docker images 便可以看到镜像2、docker save -o <tar包名>.tar <镜像名>:<tag>      ---- 将镜像保存为.tar文件,默认保存在当前目录

(2)从 tar 包导入docker镜像

1、docker load -i <tar包名>.tar     ---- 从 tar 包导入镜像导入镜像后,通过 docker images 便可看到导入的镜像。2、docker run -itd -p <本地端口>:<容器端口> <镜像名>:<tag>    ---- 通过镜像起容器

(3)案例「仅保存到tar包」

#查看容器ID
[root@localhost nginx]# docker ps -a
CONTAINER ID   IMAGE        COMMAND                   CREATED             STATUS             PORTS                                       NAMES
8e4a9fe69ef3   nginx:lnmp   "/usr/local/nginx/sb…"   About an hour ago   Up About an hour   0.0.0.0:80->80/tcp, :::80->80/tcp           nginx
a4a0028e17e9   php:lnmp     "/bin/sh -c '/usr/lo…"   About an hour ago   Up About an hour   0.0.0.0:9000->9000/tcp, :::9000->9000/tcp   php
75e85cb863da   mysql:lnmp   "/usr/sbin/init"          3 hours ago         Up 3 hours         3306/tcp                                    mysql# 将容器保存成镜像
[root@localhost nginx]# docker commit 8e4a9fe69ef3 jiajianwei/wordpress:nginx
sha256:38b898818fd95029b914009ceba88c54bd16bc5d1b03500127f14a1210cd757e
[root@localhost nginx]# docker commit a4a0028e17e9 jiajianwei/wordpress:php
sha256:73c263cec3817fe320b10ef81165f9516b7209b21efd7c9cea55ba7cb2b3b996
[root@localhost nginx]# docker commit 75e85cb863da jiajianwei/wordpress:mysql
sha256:04bd50e63925df7e7c56e2bb411376510619f78a989d0eedd33fad3b3a0a927b#查看镜像
[root@localhost nginx]# docker images
REPOSITORY             TAG       IMAGE ID       CREATED             SIZE
jiajianwei/wordpress   mysql     04bd50e63925   4 seconds ago       10.1GB
jiajianwei/wordpress   php       73c263cec381   25 seconds ago      1.35GB
jiajianwei/wordpress   nginx     38b898818fd9   47 seconds ago      598MB
nginx                  lnmp      a01cdeeb3075   About an hour ago   598MB
php                    lnmp      9e5e554f9300   2 hours ago         1.35GB
mysql                  lnmp      b61c11e30aed   3 hours ago         10.1GB
[root@localhost appsVolumn]# docker save -o mywordpress_nginx_config.tar jiajianwei/wordpress:nginx
[root@localhost appsVolumn]# docker save -o mywordpress_mysql_config.tar jiajianwei/wordpress:mysql
[root@localhost appsVolumn]# docker save -o mywordpress_php_config.tar jiajianwei/wordpress:php
[root@localhost appsVolumn]# ls
mywordpress_mysql_config.tar  mywordpress_nginx_config.tar  mywordpress_php_config.tar

5c7117ee0f0f48dc880bd88808025c51.png30150a621bb444a88d949ffe4b05a4da.png

 

 

 四、总结

快速检索PHP配置文件:

egrep -v "^(.)*#(.)*$" nginx.conf | grep -v "^$"egrep -v "^;" php.ini | egrep -v "^$"egrep -v "^;" www.conf | egrep -v "^$"

读取容器共享信息:

#表示读取nginx容器的共享信息
--volumes-from nginx: #表示读取mysql容器的共享信息
--volumes-from mysql: 

 

 

 

 

 


http://www.ppmy.cn/news/1041555.html

相关文章

RISC-V公测平台发布· CoreMark测试报告

一. CoreMark简介 CoreMark是一款用于评估CPU性能的基准测试程序&#xff0c;它包含了多种不同的计算任务&#xff0c;包括浮点数、整数、缓存、内存等方面的测试。CoreMark的测试结果通常被用来作为CPU性能的参考&#xff0c;它可以帮助开发人员和系统管理员评估不同处理器和…

JVM——JVM 垃圾回收

文章目录 写在前面本节常见面试题本文导火索 1 揭开 JVM 内存分配与回收的神秘面纱1.1 对象优先在 eden 区分配1.2 大对象直接进入老年代1.3 长期存活的对象将进入老年代1.4 动态对象年龄判定1.5 主要进行 gc 的区域 2 对象已经死亡&#xff1f;2.1 引用计数法2.2 可达性分析算…

数据结构:二叉树的链式结构的实现

1.二叉树的前序遍历 2.二叉树的中序遍历 3.二叉树的后序遍历 4.二叉树的层序遍历 5.二叉树的节点个位 6.二叉树的叶子节点个位数 7.二叉树的的k层节点数 8.查找值为x的节点 9.二叉树的销毁 10.判断二叉树是否为完全二叉树 11.求二叉树的高度h 12.通过前序遍历构建二叉树 #inclu…

安装和配置 Ansible

安装和配置 Ansible 按照下方所述&#xff0c;在控制节点 control.area12.example.com 上安装和配置 Ansible&#xff1a; 安装所需的软件包 创建名为 /home/curtis/ansible/inventory 的静态清单文件&#xff0c;以满足以下要求&#xff1a; node1 是 dev 主机组的成员 node2 …

错误记录:springboot+async异步导入excel报错

一个简单的上传excel操作&#xff0c;只不过是异步解析&#xff0c;却一直报错&#xff1a; /tmp/tomcat.7249967840843892717.80/work/Tomcat/localhost/ROOT/upload_acc8f0ff_e428_4675_8228_7d22d855d356_00000008.tmp (No such file or directory) 检查后发现写法并没有错…

nodejs 之 express 实现下载网络图片并上传到七牛云对象存储oss空间

为方便阅读&#xff0c;本文将所有逻辑放在一个函数里&#xff0c;可根据自己的情况拆分。 安装依赖 在项目根目录下运行以下命令安装依赖 npm install express qiniu axios业务逻辑 在项目根目录下创建一个名为 app.js 的文件&#xff0c;并添加以下内容 const express re…

《Go 语言第一课》课程学习笔记(四)

构建模式&#xff1a;Go Module 的 6 类常规操作 为当前 module 添加一个依赖 我们如何为一个 Go Module 添加一个新的依赖包呢&#xff1f; 如果我们要为项目增加一个新依赖&#xff1a;github.com/google/uuid&#xff0c;我们首先会更新源码&#xff1a;package mainimpor…

KVM虚拟机管理

1、创建、删除快照 关机 init0 列出快照 删除快照 2、虚拟机迁移 报错 解决&#xff1a;关闭防火墙&#xff0c;关闭selinux 其他解决办法&#xff1a;kvm热迁移使用nfs共享存储报错_莉法的博客-CSDN博客