docker command deployment LNMP - xiaoqicheng/xiaoqicheng GitHub Wiki

1、简单部署 mdocker 部署lnmp
方法一:命令方式
创建mysql容器
1.docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name cyt_mysql mysql:5.7
创建网络
2.docker network create -d bridge my-net (-d 指定网络类型,bridge voerlay--网络类型用于Swarm mode )
开启php容器并连接mysql
3.docker run -d -v /var/nginx/www/html:/var/www/html -p 9000:9000 --network my-net --name cyt_phpfpm php:7.2-fpm \ 开启nginx并连接php
在/Users/sui/docker/nginx/conf.d #touch default.conf 文件
#cat default.conf
server { listen 80; server_name localhost;

#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;

location / {
    root   /usr/share/nginx/html;
    index  index.php index.html index.htm;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    fastcgi_pass   cyt_phpfpm:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
    include        fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}

4.docker run --name cyt_nginx -p 80:80 -d \
-v /Users/sui/www:/usr/share/nginx/html:ro \
-v /Users/sui/docker/nginx/conf.d:/etc/nginx/conf.d:ro \
--network my-ney \
nginx

注: /Users/sui/www 为宿主机项目目录 /var/www/html 为cyt_phpfpm容器中的项目目录 /usr/share/nginx/html 为cyt_nginx容器的项目目录

5验证 在浏览器直接访问 http://localhost/index.php