使用docker搭建lnmp环境

若家境殷实,谁愿颠沛流离。

docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
version: '3'

services:
nginx:
hostname: nginx
image: nginx
ports:
- 8000:80
networks:
- lnmp
volumes:
- ./wwwroot:/usr/share/nginx/html
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf.d:/etc/nginx/conf.d/
php:
hostname: php
image: php:7.2.6-fpm
networks:
- lnmp
volumes:
- ./wwwroot:/usr/share/nginx/html
mysql:
hostname: mysql
image: mysql:5.7.22
ports:
- 3307:3306
networks:
- lnmp
volumes:
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/data:/var/lib/mysql
command: --character-set-server=utf8mb4
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wp
MYSQL_USER: yangzie
MYSQL_PASSWORD: 123456
networks:
lnmp:
driver: bridge

nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm index.php;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}

}

mysql

1
mysql -h47.98.174.48 -P 3307 -uroot -p123456

目录

1
2
3
4
5
6
7
8
9
10
11
12
13
├── docker-compose.yml
├── mysql
│   ├── conf
│   └── data
├── nginx
│   ├── conf.d
│   └── nginx.conf
├── php
│   └── ini
└── wwwroot
├── index.php
└── tp5

截图

注意点

  • php容器也要配置目录映射, 不然找不到php文件
  • nginx的server配置中监听9000端口:php:9000
  • 找不到的配置可以在Dockerfile文件中找