服务器之家:专注于服务器技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - 服务器知识 - 使用docker制作分布式lnmp 镜像

使用docker制作分布式lnmp 镜像

2021-08-05 18:03小白的成功进阶之路 服务器知识

最近在学习docker相关知识,顺便把docker制作分布式lnmp 镜像的过程分享给大家,包括Nginx配置文件和PHP文件的修改代码也一并给出,感兴趣的朋友跟随小编一起看看吧

LNMP 是代表 Linux 系统下的 Nginx、Mariadb、PHP 相结合而构建成的动态网站服务器架构。下面使用docker制作分布式lnmp 镜像

一、docker 分布式 lnmp 镜像制作

 

1、运行Nginx、MySQL、PHP容器

  1. #关闭防火墙及核心防护 
  2. systemctl disable firewalld 
  3. systemctl stop firewalld 
  4. setenforce 0 
  5.  
  6. #查看3306、80及9000端口是否被占用 
  7. ss -natp | grep 3306 
  8. ss -natp | grep 80 
  9. ss -natp | grep 9000 
  10.  
  11. #创建自定义网络 
  12. docker network create -d bridge --subnet 172.168.184.0/24 --gateway 172.168.184.1 lnmp 
  13.  
  14. #运行Nginx容器 
  15. docker run -itd --name nginx --network lnmp -p 80:80 --ip 172.168.184.10 nginx:1.12.0 
  16.  
  17. #运行MySQL容器 
  18. docker run -itd --name mysql --network lnmp -p 3306:3306 --ip 172.168.184.20 -e MYSQL_ROOT_PASSWORD=010230 mysql:5.7 
  19.  
  20. #运行PHP容器 
  21. docker run -itd --name phpfpm --network lnmp -p 9000:9000 --ip 172.168.184.30 php:7.1-fpm 

使用docker制作分布式lnmp 镜像

使用docker制作分布式lnmp 镜像

使用docker制作分布式lnmp 镜像

2、修改Nginx配置文件和PHP文件

  1. docker exec -it nginx /bin/bash 
  2. echo -e "server { 
  3.     listen       80; 
  4.     server_name  localhost; 
  5.     location / { 
  6.         root   /usr/share/nginx/html; 
  7.         index  index.html index.htmi index.php; 
  8.     } 
  9.     error_page   500 502 503 504  /50x.html; 
  10.     location = /50x.html { 
  11.         root   /usr/share/nginx/html; 
  12.     } 
  13.     location ~ \.php$ { 
  14.         root           /usr/share/nginx/html; 
  15.         fastcgi_pass   172.168.184.30:9000; 
  16.         fastcgi_index  index.php; 
  17.         fastcgi_param  SCRIPT_FILENAME  \$document_root\$fastcgi_script_name; 
  18.         include        fastcgi_params; 
  19.     } 
  20. }" > /etc/nginx/conf.d/default.conf 
  21.  
  22. nginx -s reload 
  23.  
  24. docker exec -it phpfpm /bin/bash 
  25. mkdir -p /usr/share/nginx/html 
  26. echo "<?php 
  27. phpinfo(); 
  28. ?>" > /usr/share/nginx/html/index.php 

使用docker制作分布式lnmp 镜像

使用docker制作分布式lnmp 镜像

4、进行测试

虚拟机输入localhost/index.php

使用docker制作分布式lnmp 镜像

本机输入 192.168.184.70/index.php (我虚拟机地址是192.168.184.70)

使用docker制作分布式lnmp 镜像

以上就是使用docker制作分布式lnmp 镜像的详细内容,更多关于docker分布式lnmp 镜像的资料请关注服务器之家其它相关文章!

原文地址:https://blog.csdn.net/Lucien010230/article/details/117395270

延伸 · 阅读

精彩推荐