当前位置: 首页 > 工具软件 > WNMP > 使用案例 >

Docker Wnmp 搭建

汤枫涟
2023-12-01

1.下载Docker for windows

https://hub.docker.com/editions/community/docker-ce-desktop-windows

2.通过power shell 拉取镜像

  docker pull mysql:5.6
  docker pull php:7.1
  docker pull nginx:1.10.3

3.启动指定 镜像的容器

   docker run -d -v E:\wnmp\mysql-log:/var/log/mysql/ -v E:\wnmp\mysql-conf:/etc/mysql/ -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name mysql mysql:5.6
   
  docker run -d -v E:\wnmp\php71-log:/usr/local/var/log -v E:\wnmp\www:/var/www -p 9000:9000 --link mysql:mysql --name php71 php:7.1-fpm
  
   docker run -d -p 80:80 -v E:\wnmp\www:/var/www -v E:\wnmp\nginx-log:/var/log/nginx/ --name nginx nginx:1.10.3
   docker run 命令解释
   -d: 后台运行容器,并返回容器ID;
   -p: 指定端口映射,格式为:主机(宿主)端口:容器端口;
   --volume , -v: 绑定一个卷
   -e username="ritchie": 设置环境变量;
   --link=[]: 添加链接到另一个容器;

详细:https://www.runoob.com/docker/docker-run-command.html

4.拷贝对应的挂载目录及文件

  docker cp mysql:/var/log/mysql/ E:\wnmp\mysql-log
  docker cp mysql:/etc/mysql/  E:\wnmp\mysql-conf
  

  docker cp php71:/usr/local/var/log E:\wnmp\php71-log
  docker cp php71:/var/www/html  E:\wnmp\www
  

  docker cp nginx:/var/log/nginx/ E:\wnmp\nginx-log
  docker cp nginx:/var/www/html E:\wnmp\www
  

 将配置文件拷贝出来
 docker cp nginx:/etc/nginx/conf.d/default.conf E:\wnmp\www\default.conf
 
 修改完拷贝回去
 docker cp E:\wnmp\www\default.conf nginx:/etc/nginx/conf.d/default.conf

5.default.conf文件配置

server {
    listen       80;
    server_name  localhost;

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

    location / {
        root   /var/www;
        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$ {
        root           /var/www;
        fastcgi_pass   192.168.11.133:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/$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;
    #}
}

 类似资料: