我正在用 Laravel、mysql 和 nginx 构建一个项目
但是我的端口绑定可能有问题。 当我运行
docker ps
端口正常
我的
docker-compose.yml
version: '3'
networks:
laravel:
driver: bridge
services:
modhub:
build: .
container_name: modhub
restart: unless-stopped
tty: true
volumes:
- ./:/var/www
- ./local-config/php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- laravel
nginx:
image: nginx:stable
container_name: nginx-modhub
restart: unless-stopped
tty: true
ports:
- "8020:80"
- "448:443"
volumes:
- ./:/var/www
- ./local-config/nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- laravel
在
Dockerfile
我暴露了PORT 8020
nginx 配置文件 (
default.conf
)
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass modhub:8020;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Docker文件
FROM php:8.1.4-fpm
WORKDIR /var/www
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libonig-dev \
libzip-dev \
nodejs npm
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
USER 1000
EXPOSE 8020
ENTRYPOINT ["php-fpm"]