首頁 > 資料庫 > mysql教程 > PHP/MySQL/Nginx/Redis 應用 Docker

PHP/MySQL/Nginx/Redis 應用 Docker

DDD
發布: 2024-10-09 10:13:30
原創
615 人瀏覽過

PHP/MySQL/Nginx/Redis Application Docker

*- 建立 Dockerfile *

FROM php:8.3-fpm

RUN apt-get update && \
    apt-get install -y git unzip iputils-ping && \
    docker-php-ext-install pdo pdo_mysql

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

RUN composer global require laravel/installer

ENV PATH="$PATH:$HOME/.composer/vendor/bin"

WORKDIR /var/www
登入後複製

- 建立 docker-compose.yml

version: '3.8'
services:
  app:
    image: php:8.3-fpm
    container_name: ap-name-app
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./docker/php/php.ini:/usr/local/etc/php/php.ini
    networks:
      - laravel
    depends_on:
      - mysql
      - redis

  nginx:
    image: nginx:alpine
    container_name: app-name-nginx
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
    networks:
      - laravel
    depends_on:
      - app

  mysql:
    image: mysql:8.0
    container_name: app-name-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: database
      MYSQL_USER: user
      MYSQL_PASSWORD: password
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
    networks:
      - laravel

  redis:
    image: redis:alpine
    container_name: app-name-redis
    ports:
      - "6380:6379"
    networks:
      - laravel

networks:
  laravel:
    driver: bridge

volumes:
  mysql-data:
登入後複製

建立 nginx.conf

worker_processes auto;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    sendfile on;
    keepalive_timeout 65;
    server_tokens off;

    server {
        listen 80;
        server_name localhost;

        root /var/www/public;
        index index.php index.html index.htm;

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

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi.conf;
        }

        location ~ /\.ht {
            deny all;
        }
    }
}
登入後複製

以上是PHP/MySQL/Nginx/Redis 應用 Docker的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板