我目前正在尝试将 Laravel 应用程序 docker 化,我已成功创建了 Dockerfile 和 docker-compose.yml,其中包含所需的依赖项。但是,我很难让 php-fpm 启动并显示我的应用程序。
Dockerfile
# Set master image
FROM php:8.0-fpm-alpine
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/html/
# Set working directory
WORKDIR /var/www/html
# Install Additional dependencies
RUN apk update && apk add --no-cache \
build-base shadow vim curl \
php8 \
php8-fpm \
php8-common \
php8-pdo \
php8-pdo_mysql \
php8-mysqli \
php8-mbstring \
php8-xml \
php8-openssl \
php8-json \
php8-phar \
php8-zip \
php8-gd \
php8-dom \
php8-session \
php8-zlib \
nodejs \
npm
# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-enable pdo_mysql
# Install PHP Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Remove Cache
RUN rm -rf /var/cache/apk/*
# Add UID '1000' to www-data
RUN usermod -u 1000 www-data
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html
# Change current user to www
USER www-data
# Install app dependencies
COPY package.json /var/www/html/
RUN npm install
RUN npm run dev
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
docker-compose.yml
version: '3'
services:
#Laravel App
app:
build:
context: .
dockerfile: Dockerfile
image: heychazza/joinservers.com
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www/html
expose:
- "9000:80"
volumes:
- ./:/var/www/html
networks:
- mynet
#Nginx Service
nginx:
image: nginx:alpine
container_name: nginx
restart: unless-stopped
tty: true
ports:
- "8080:80"
volumes:
- ./:/var/www/html
- ./deployment/nginx/conf.d/:/etc/nginx/conf.d/
#- ./nginx/ssl/:/etc/nginx/ssl/
depends_on:
- app
networks:
- mynet
#MySQL Service
db:
image: mariadb:latest
container_name: db
restart: unless-stopped
tty: true
ports:
- "33060:3306"
environment:
MYSQL_DATABASE: laraveldb
MYSQL_USER: laravel
MYSQL_PASSWORD: laravelpassworddb
MYSQL_ROOT_PASSWORD: rootpasswordmysql
MYSQL_ROOT_HOST: '%'
volumes:
- mysqldata:/var/lib/mysql/
networks:
- mynet
#Docker Networks
networks:
mynet:
driver: bridge
#Volumes
volumes:
mysqldata:
driver: local
我在做什么?我正在 MacBook 上运行 Docker,并希望将其部署到生产 Debian 机器上。
我对 docker 还很陌生,所以如果我遗漏了什么,请原谅。
答案1
解决了,原来我需要将 php 位置更改为。
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass app:9000;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}