단일 Docker 컨테이너에서 PHP 8, NGINX 및 PHP-fpm 실행
여기에서 nginx 구성 및 샘플 프로젝트를 찾을 수 있습니다: Github
전체 가이드 문서: How to setup PHP 8, NGINX, PHP-FPM and Alpine with Docker
도커파일
가장 먼저 필요한 것은 Dockerfile입니다. Dockerfile은 사용자가 이미지를 어셈블하기 위해 명령줄에서 호출할 수 있는 모든 명령이 포함된 텍스트 문서입니다. 다음 Dockerfile을 사용하여 이미지를 빌드합니다.
# First, We need an Operating System for our docker. We choose alpine.
FROM alpine:3.16.2
# Next, Update Alpine OS
RUN apk update && apk upgrade
# Next, we need to install utilities inside alpine, we can achieve this by type RUN then, the alpine command.
# Install apline utilities and php depedencies
RUN apk add --no-cache \
    bash \
    php8 \ 
    php8-fpm \ 
    php8-opcache \
    php8-gd \
    php8-zlib \
    php8-curl \
    php8-bcmath \
    php8-ctype \
    php8-iconv \
    php8-intl \
    php8-json \
    php8-mbstring \
    php8-mysqlnd \
    php8-openssl \
    php8-pdo \
    php8-pdo_mysql \
    php8-pdo_pgsql \
    php8-pdo_sqlite \
    php8-phar \
    php8-posix \
    php8-session \
    php8-soap \
    php8-xml \
    php8-zip \
    libmcrypt-dev \
    libltdl 
# Next, Install nginx on alpine official guide in nginx official site. I just copied and paste what's on the site guide for installing nginx on alpine.
# https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/
RUN apk add openssl curl ca-certificates
# To set up the apk repository for stable nginx packages, run the command:
RUN printf "%s%s%s\n" \
"http://nginx.org/packages/alpine/v" \
`egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release` \
"/main" \
| tee -a /etc/apk/repositories
# Import an official nginx signing key so apk could verify the packages authenticity. Fetch the key:
RUN curl -o /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub
# Verify that the downloaded file contains the proper key:
RUN openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout
# Move the key to apk trusted keys storage
RUN mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/
# Now, install nginx
RUN apk add nginx
# Install PHP Composer, If you use composer, you can uncomment this one.
# RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# copy project file to nginx inside docker.
COPY ./src /usr/share/nginx/html/project
# Copy default config and paste it into nginx config path inside docker.
COPY ./nginx-configs/default.conf /etc/nginx/conf.d/default.conf
# Expose port to be visible outside the container.
EXPOSE 80
EXPOSE 443
STOPSIGNAL SIGTERM
# Execute startup command.
# Start php-fpm8 and nginx through bash terminal.
CMD ["/bin/bash", "-c", "php-fpm8 && chmod 755 /usr/share/nginx/html/* && nginx -g 'daemon off;'"]
이제 docker-compose가 필요합니다.
Docker Compose는 다중 컨테이너 애플리케이션을 정의하고 실행하는 데 사용되는 도구입니다. Compose에서는 YAML 파일을 사용하여 애플리케이션의 서비스를 구성합니다. 그런 다음 단일 명령으로 구성에서 모든 서비스를 만들고 시작합니다.
version: "1.0"
services:
  backend:
    # Specify Image name
    image: backend
    # Specify Container name
    container_name: backend
    # specify context and dockerfile to build
    build: 
      #Docker context is path where dockerfile is located.
      context: ./
      #specify Dockerfile to build.
      dockerfile: Dockerfile
    #expose ports
    ports:
      - "8082:80"
      - "443:43"
    #persistent volume
    volumes: 
      - ./src:/usr/share/nginx/html/project
프로젝트 터미널에서 스크립트를 실행합니다.
docker-compose up -d
사이트 소스: Review Curious
Reference
이 문제에 관하여(단일 Docker 컨테이너에서 PHP 8, NGINX 및 PHP-fpm 실행), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/mickalannz/run-php-8-nginx-and-php-fpm-in-single-docker-container-4pbd텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)