我目前正在嘗試對 Laravel 應用程式進行 dockerise,我已成功使用我需要的依賴項建立了 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;
}