使用docker lnmp镜像包部署搭建laravel项目

下载镜像包

访问https://registry.hub.docker.c... lnmp镜像地址
打开终端

docker pull 2233466866/lnmp

启动docker相关配置

docker run -it --privileged --name=lnmp -p 20016:80 -p 3306:3306  -v ~/www:/www  -v ~/lnmp-data/env/mysqlData:/data/mysql -v ~/lnmp-data/env/nginx.conf:/usr/local/nginx/conf/nginx.conf 2233466866/lnmp

说明:

  • ~/www 是工作目录
  • ~/lnmp-data/env/mysqlData 是数据库目录
  • ~/lnmp-data/env/nginx.conf 是nginx是配置文件
  • 20016是本地端口

我的一个项目 目录是~/www/laravel,所以nginx.conf配置文件的内容如下:

user                    www;
worker_processes        auto;
worker_cpu_affinity     auto;
pid                     logs/nginx.pid;

events {
    worker_connections  102400;
}

http {
    charset             utf-8;
    server_tokens       off;

    log_format  main    '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';

    include             mime.types;
    default_type        application/octet-stream;

    client_max_body_size 20M;

    sendfile            on;
    keepalive_timeout   20;

    gzip                on;
    gzip_vary           on;
    gzip_comp_level     1;
    gzip_types          text/css application/javascript application/json image/png image/webp image/apng image/jpeg image/x-icon;

    error_log           /www/z_error.log;
    access_log          /www/z_$host.log main;

    server {
        listen      80;
        server_name www.test.com;
        root        /www/laravel/public;
        index index.html index.htm index.php

        autoindex on;
        
        location / {
            index   index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~* \.php {
            include                 fastcgi_params;
            fastcgi_index           index.php;
            fastcgi_pass            127.0.0.1:9000;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param           PATH_INFO       $fastcgi_path_info;
            fastcgi_param           SCRIPT_NAME     $fastcgi_script_name;
            fastcgi_param           SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
}

mysql设置

进入docker中

docker exec -it 容器id /bin/bash
cat /var/log/mysqld.log|grep 'A temporary password'

就会出现密码,用密码连接到mysql中,

alter user user() identified by "ur93Y*Qt,?hN";
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ur93Y*Qt,?hN' WITH GRANT OPTION;
FLUSH PRIVILEGES;

这样就可以在本地用客户端连接到docker容器中的mysql了。

打开chrome,输入localhost:20016,应该可以看到内容了。

你可能感兴趣的:(使用docker lnmp镜像包部署搭建laravel项目)