野生程序员
发布于 2022-08-26 / 385 阅读 / 0 评论 / 0 点赞

使用docker一键启动php nginx mysql 开发 运行 环境

1

文件
./docker-compose.yml

version: '3'
services:
  # 定义web5_php容器   docker pull nanoninja/php-fpm:7.2.15
  web5_php:
    image: nanoninja/php-fpm:7.2.15
    container_name: web5_php           #容器名称
    # ports:
    #   - "55557:9000"
    volumes:
      - "./web5_php:/var/www/html"
    restart: always
    depends_on:                     # 启动前置条件
      - web5_mysql
    networks:
      - web5

  # 定义nginx容器
  web5_nginx:
    image: nginx
    container_name: web5_nginx
    depends_on:
      - web5_php
    volumes:
      - "./config/nginx/config:/etc/nginx/conf.d"
      - "/etc/hosts:/etc/hosts"
      - "./web5_php:/var/www/html"
      - "./config/nginx/log:/var/log/nginx"
    ports:
      - "55556:80"
    restart: always
    networks:
      - web5


  # 容器2
  web5_mysql:
    image: mysql:8.0.21       # 如果您是 arm64 架构:如 MacOS 的 M1,请修改镜像为 image: mysql/mysql-server:8.0.21
    container_name: web5_mysql
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password #设置utf8字符集 加密类型
    restart: always
    ports:
      - "55555:3306"  # host物理直接映射端口为 55555
    environment:
      MYSQL_ROOT_PASSWORD: 'ddd665655**454564' # root管理员用户密码

      MYSQL_DATABASE: 'ddd' # 初始化启动时要创建的数据库的名称
      MYSQL_USER: "ddd"    # 初始化启动时要创建的数据库的用户名
      MYSQL_PASSWORD: "465465*sdfs*df**"  # 初始化启动时要创建的数据库的密码
    volumes:
      - ./web5_mysql:/var/lib/mysql
    networks:
      - web5



networks:
  web5:

# 启动
# docker-compose up -d

2

文件夹
./web5_php
放php文件

3

文件 放 nginx 配置
./config/nginx/config/default.conf

server {
    listen       80;
    server_name  localhost;

    root /var/www/html;
    index index.php;
    error_log /var/log/nginx/localhost.log;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   web5_php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

}

仓库地址

https://gitee.com/wdbj/docker_php


评论