关于docker:使用docker-lnmp镜像包部署搭建laravel项目

57次阅读

共计 1796 个字符,预计需要花费 5 分钟才能阅读完成。

下载镜像包

拜访 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, 应该能够看到内容了。

正文完
 0