• docker lnmp 配置


    镜像下载

    PHP镜像下载

    docker pull php:7.4.8-fpm
    

    Nginx镜像下载

    docker pull nginx
    

    Mysql镜像下载

    docker pull mysql:5.7 
    

    验证

    docker images
    

    结果如图:


     
     

    制作配置文件

    创建 ~/nginx/conf/ 配置等目录

    mkdir -p  ~/nginx/logs ~/nginx/conf
    

    创建nginx的配置文件

    vim ~/nginx/conf/nginx.conf
    

    配置文件如下:

    server {
        listen       80;
        server_name  localhost;
    
        location / {
            root   /webroot/;
            index  index.html index.htm index.php;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /webroot/;
        }
    
        location ~ \.php$ {
            fastcgi_pass   php:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    配置文件说明:

    • php:9000: 表示 php 服务的 URL。
    • /webroot/: 是 php 容器中 php 文件的存储路径,映射到本地的 ~/Documents/code 目录。

    在 ~/Documents/code 目录下创建index.php

    <?php
        phpinfo();
    ?>
    

    运行Mysql容器

    docker run -it -d -p8066:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql57 -v ~/Documents/code/mysqldata:/usr/local/mysql mysql:5.7
    

    运行PHP容器

    docker run --name php7 -v ~/Documents/code:/webroot -d php:7.4.8-fpm
    

    运行Nginx容器

    docker run --name mynginx -p 80:80 -v ~/Documents/code:/webroot -v ~/nginx/conf:/etc/nginx/conf.d --link php7:php --link mysql57:mysql -d nginx
    

    命令说明:

    • --name mynginx : 将容器命名为 mynginx
    • -v ~/Documents/code:/webroot : 将本地目录~/Documents/code 挂载到容器的/webroot目录下

    验证

    浏览器访问 localhost


     
     

    配置虚拟域名

    修改nginx的配置文件

    vim ~/nginx/conf/nginx.conf
    
    server {
        listen       80;
        server_name  mytest.com;
    
        location / {
            root   /webroot/test/;
            index  index.html index.htm index.php;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /webroot/test/;
        }
    
        location ~ \.php$ {
            fastcgi_pass   php:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /webroot/test/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    重启容器

    docker restart mynginx
    

    修改hosts文件

    sudo vim /ets/hosts
    

    增加

    127.0.0.1 mytest.com
    

    测试

    在~/Documents/code下创建test文件夹,在该文件夹新建一个index.php

    <?php
    echo "hello world";
    ?>
    

    验证

    浏览器访问 mytest.com


     


    作者:程序员Ameng
    链接:https://www.jianshu.com/p/885d5249f4e4
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    Python3 B格注释
    python 安装模块时提示报错:Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)
    sed的使用(数据的截取与插入)
    常见软件的安装
    淘宝镜像
    搭建 Node.js 开发环境
    解决 /lib64/libc.so.6: version `GLIBC_2.14' not found 的问题
    linux下 执行命令时提示cannot execute binary file
    web页面 显示 Resource interpreted as Stylesheet but transferred with MIME type text/plain的错误警告
    python+QT designer 做图形化界面EXE程序
  • 原文地址:https://www.cnblogs.com/weixinsb/p/15603133.html
Copyright © 2020-2023  润新知