【Dockerfile镜像实战】构建LNMP环境并运行Wordpress网站平台

【Dockerfile镜像实战】构建LNMP环境并运行Wordpress网站平台

Nginx部署

shell 复制代码
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
shell 复制代码
[root@localhost ~]# docker pull centos:7
shell 复制代码
[root@localhost ~]# docker images
shell 复制代码
cd /opt
mkdir nginx
cd nginx
vim Dockerfile


shell 复制代码
vim nginx.conf
shell 复制代码
cd /opt/nginx
rz -E //将nginx的安装包导入进来
mkdir html
cd html
rz -E //将wordpress的安装包导入进来
tar xf wordpress-4.9.4-zh_CN.tar.gz //解压文件
rm -rf wordpress-4.9.4-zh_CN.tar.gz //删除压缩包
shell 复制代码
[root@localhost nginx]# docker build -t nginx:lnmp .
[root@localhost nginx]# docker images
shell 复制代码
docker run -d --name nginx -p 80:80 -v /opt/nginx/html:/usr/local/nginx/html -v /opt/nginx/nginx.conf:/usr/local/nginx/conf/nginx.conf --net lnmpnetwork --ip 172.18.0.10 nginx:lnmp

docker ps -a
shell 复制代码
cd /opt/nginx/html
vim index.html  
//新建一个测试网页,查看nginx是否能正常运行
shell 复制代码
[root@localhost nginx]# docker exec -it nginx bash
[root@d94d0066c01a /]# 
[root@d94d0066c01a /]# cd /usr/local/nginx/html/
[root@d94d0066c01a html]# 
[root@d94d0066c01a html]# ls
wordpress

MySQL部署

shell 复制代码
[root@localhost nginx]# cd /opt
[root@localhost opt]# 
[root@localhost opt]# ls
containerd  nginx  rh
[root@localhost opt]# 
[root@localhost opt]# mkdir mysql php
[root@localhost opt]# 
[root@localhost opt]# ls
containerd  mysql  nginx  php  rh
[root@localhost opt]# 
[root@localhost opt]# cd mysql/
[root@localhost mysql]# 
[root@localhost mysql]# ls
[root@localhost mysql]# 
[root@localhost mysql]# rz -E
rz waiting to receive.
[root@localhost mysql]# 
[root@localhost mysql]# touch Dockerfile
[root@localhost mysql]# 
[root@localhost mysql]# ls
Dockerfile  mysql-boost-5.7.41.tar.gz
shell 复制代码
[root@localhost mysql]# vim Dockerfile 
shell 复制代码
[root@localhost mysql]# vim my.cnf
shell 复制代码
[root@localhost mysql]# docker build -t mysql:lnmp .
shell 复制代码
[root@localhost docker]# docker run --name mysql -d --privileged -v /usr/local/mysql --network lnmpnetwork --ip 172.18.0.20 mysql:lnmp
13f2bb048679a6d4042f5f235e794305ca6e8c2912d8b13b8b8d891c0911a34f
[root@localhost docker]# 
[root@localhost docker]# docker ps -a
CONTAINER ID   IMAGE        COMMAND                   CREATED          STATUS          PORTS                                        NAMES
13f2bb048679   mysql:lnmp   "/usr/local/mysql/bi..."   17 seconds ago   Up 10 seconds   3306/tcp                                     mysql
d94d0066c01a   nginx:lnmp   "/usr/local/nginx/sb..."   2 hours ago      Up 46 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp   nginx
[root@localhost docker]# 
shell 复制代码
[root@13f2bb048679 mysql]# mysql

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit;
Bye
[root@13f2bb048679 mysql]# 
shell 复制代码
[root@13f2bb048679 mysql]# mysqladmin -u root -p password "abc123"
shell 复制代码
[root@13f2bb048679 mysql]# mysql -u root -pabc123

PHP部署

shell 复制代码
[root@localhost mysql]# 
[root@localhost mysql]# cd ../php/
[root@localhost php]# 
[root@localhost php]# ls
[root@localhost php]# 
[root@localhost php]# rz -E
rz waiting to receive.
[root@localhost php]# 
[root@localhost php]# ls
php-7.1.10.tar.bz2
[root@localhost php]# 
shell 复制代码
[root@localhost php]# vim Dockerfile 
[root@localhost php]# 
[root@localhost php]# 
[root@localhost php]# vim php-fpm.conf 
[root@localhost php]# 
[root@localhost php]# vim php.ini 
[root@localhost php]# 
[root@localhost php]# vim www.conf 
[root@localhost php]# 




shell 复制代码
[root@localhost php]# docker build -t php:lnmp .
shell 复制代码
[root@localhost php]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
php          lnmp      f969ee0fe328   2 minutes ago   421MB
mysql        lnmp      03aa4c425566   3 hours ago     4.24GB
nginx        lnmp      01356f501e0c   6 hours ago     208MB
centos       7         eeb6ee3f44bd   2 years ago     204MB
[root@localhost php]# 
[root@localhost php]# docker run --name=php -d -p 9000:9000 --volumes-from mysql --volumes-from nginx --network lnmpnetwork --ip 172.18.0.30 php:lnmp
fc67bd7f644ba8b704398db992420fcf80662b50b0a1ab28a9200af6ff73f400
[root@localhost php]# 
[root@localhost php]# docker ps -a
CONTAINER ID   IMAGE        COMMAND                   CREATED          STATUS          PORTS                                        NAMES
fc67bd7f644b   php:lnmp     "/usr/local/php/sbin..."   12 seconds ago   Up 11 seconds   0.0.0.0:9000->9000/tcp, :::9000->9000/tcp    php
13f2bb048679   mysql:lnmp   "/usr/local/mysql/bi..."   3 hours ago      Up 3 hours      3306/tcp                                     mysql
d94d0066c01a   nginx:lnmp   "/usr/local/nginx/sb..."   5 hours ago      Up 4 hours      0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp   nginx
[root@localhost php]# 
shell 复制代码
[root@localhost php]# docker exec -it nginx bash
[root@d94d0066c01a /]# 
[root@d94d0066c01a /]# cd /usr/local/nginx/html/
[root@d94d0066c01a html]# 
[root@d94d0066c01a html]# ll
total 4
drwxr-xr-x. 5 nobody 65534 4096 Feb  8  2018 wordpress
[root@d94d0066c01a html]# 
[root@d94d0066c01a html]# chown -R nginx:nginx wordpress/
[root@d94d0066c01a html]# 
[root@d94d0066c01a html]# ll
total 4
drwxr-xr-x. 5 nginx nginx 4096 Feb  8  2018 wordpress
[root@d94d0066c01a html]# 
shell 复制代码
[root@13f2bb048679 /]# mysql -u root -p
Enter password: 
mysql> 
mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.00 sec)

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

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

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
shell 复制代码
浏览器访问:
http://192.168.190.120/wordpress/index.php





相关推荐
Hqst_Kevin41 分钟前
Hqst 品牌 H81801D 千兆 DIP 网络变压器在光猫收发器机顶盒中的应用
运维·服务器·网络·5g·网络安全·信息与通信·信号处理
honey ball1 小时前
仪表放大器AD620
运维·单片机·嵌入式硬件·物联网·学习
秋已杰爱1 小时前
进程间关系与进程守护
运维·服务器
Flying_Fish_roe2 小时前
linux-软件包管理-包管理工具(Debian 系)
linux·运维·debian
BLEACH-heiqiyihu2 小时前
红帽9中nginx-源码编译php
运维·nginx·php
666786662 小时前
Mysql高级篇(中)—— SQL优化
linux·运维·服务器·数据库·sql·mysql
企业管理8MSaaS2 小时前
了解CRM销售自动化:类型、优势、策略和工具
运维·自动化
创小董3 小时前
智能机巢+无人机:自动化巡检技术详解
运维·自动化·无人机
henanxiaoman3 小时前
SaltStack自动化运维部署
运维·自动化·saltstack
Run_Snails4 小时前
hcia-openEuler V1.0师资题库-试卷3
运维·服务器·网络