Dockerfile与docker-compose搭建php环境

 

目录结构

 

php.conf文件内容

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
41
42
43
44
45
46
47
server {
    listen  80;
    server_name localhost;
 
    location / {
        root    /usr/share/nginx/html/web;
        index   index.php index.html index.htm;
    }
 
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
        root    /usr/share/nginx/html/web;
    }
 
    location ~ .php$ {
        fastcgi_pass    php:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /www/web/$fastcgi_script_name;
        include     fastcgi_params;
    }
}
 
server {
    listen  80;
    server_name docker.web1.com;
 
    location / {
        root    /usr/share/nginx/html/web1/public;
        index   index.php index.html index.htm;
 
        if (!-f $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
        }
    }
 
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
        root    /usr/share/nginx/html/web1/public;
    }
 
    location ~ .php$ {
        fastcgi_pass    php:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /www/web1/public/$fastcgi_script_name;
        include     fastcgi_params;
    }
}

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
version: "3.9"
services:
  nginx:
    image: nginx
    privileged: true
    ports:
      - "80:80"
    volumes:
      - /Users/yf/Sites/www:/usr/share/nginx/html
      - /Users/yf/Sites/www/conf:/etc/nginx/conf.d
      - /Users/yf/Sites/www/logs:/var/log/nginx
    networks:
      - web-net
  php:
    #    image: phpdockerio/php72-fpm
    build: .
    privileged: true
    volumes:
      - /Users/yf/Sites/www:/www
    networks:
      - web-net
  mysql:
    #    image: mysql
    image: mysql/mysql-server:latest
    command:
      - "--default-authentication-plugin=mysql_native_password"
    volumes:
      - /Users/yf/Sites/www/mysql:/var/lib/mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
    networks:
      - web-net
networks:
  web-net:

Dockerfile文件配置内容

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
FROM php:7.2-fpm
 
RUN docker-php-ext-install pdo_mysql \
 
&& docker-php-ext-install mysqli \
 
&& docker-php-ext-install exif \
 
&& docker-php-ext-install bcmath \
 
&& pecl install -o -f redis \
 
&& docker-php-ext-enable redis
 
# 镜像作者
MAINTAINER fy
 
# 设置 python 环境变量
ENV PYTHONUNBUFFERED 1
 
# 设置容器内项目路径
ENV PROJECTPATH=/www
 
# 在容器内创建django文件夹
RUN mkdir -p $PROJECTPATH
 
# 设置容器内工作目录
WORKDIR $PROJECTPATH
 
# 将当前目录文件加入到容器工作目录中(. 表示当前宿主机目录)
ADD . $PROJECTPATH

 

posted @   程序员小艺  阅读(227)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示