현재 Laravel 애플리케이션을 dockerise하려고 하고 있으며 필요한 종속성을 사용하여 Dockerfile과 docker-compose.yml을 만들었습니다. 그러나 나는 내 응용 프로그램을 표시하기 위해 php-fpm을 실행하는 데 어려움을 겪고 있습니다.
도커파일
# 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;
}