当前位置:   article > 正文

docker-compose构建lnmp_docker-compose lnmp

docker-compose lnmp

一、准备镜像

  1. docker pull mysql:5.7
  2. docker pull nginx
  3. docker pull cytopia/php-fpm-5.6

二、创建文件夹

  1. mkdir lnmp
  2. cd lnmp/
  3. mkdir {conf,html}

三、编写配置文件

   1.写静态页面

  1. vim html/index.html
  2. this is test !!!! hello world

2.编写php测试页面

  1. vim test.php
  2. <?php
  3. phpinfo();
  4. ?>

3.编写连接数据库页面

  1. vim html/dbtest.php
  2. <?php
  3. $conn=mysql_connect("mysql","root","123456");
  4. if ($conn) echo "ok";
  5. mysql_close();
  6. ?>

4.修改nginx配置文件

  1. vim conf/default.conf
  2. server {
  3. listen 80;
  4. listen [::]:80;
  5. server_name localhost;
  6. #charset koi8-r;
  7. #access_log /var/log/nginx/host.access.log main;
  8. location / {
  9. root /usr/share/nginx/html;
  10. index index.html index.php index.htm;
  11. }
  12. #error_page 404 /404.html;
  13. # redirect server error pages to the static page /50x.html
  14. #
  15. error_page 500 502 503 504 /50x.html;
  16. location = /50x.html {
  17. root /usr/share/nginx/html;
  18. }
  19. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  20. #
  21. #location ~ \.php$ {
  22. # proxy_pass http://127.0.0.1;
  23. #}
  24. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  25. #
  26. location ~ \.php$ {
  27. # root html;
  28. fastcgi_pass php:9000;
  29. fastcgi_index index.php;
  30. fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
  31. include fastcgi_params;
  32. }
  33. # deny access to .htaccess files, if Apache's document root
  34. # concurs with nginx's one
  35. #
  36. #location ~ /\.ht {
  37. # deny all;
  38. #}
  39. }

四、编写docker-compose.yml

  1. version: "3"
  2. services:
  3. nginx:
  4. image: nginx
  5. ports:
  6. - 80
  7. volumes:
  8. - /root/lnmp/conf/default.conf:/etc/nginx/conf.d/default.conf
  9. - /root/lnmp/html/:/usr/share/nginx/html
  10. depends_on:
  11. - php
  12. php:
  13. image: cytopia/php-fpm-5.6
  14. volumes:
  15. - /root/lnmp/html/:/var/www/html/
  16. mysql:
  17. image: mysql:5.7
  18. environment:
  19. - MYSQL_ROOT_PASSWORD=123456

五、运行并验证

docker-compose up -d

 1.网页验证

 2.数据库连接验证

3.php页面验证

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/829087
推荐阅读
相关标签
  

闽ICP备14008679号