簡體   English   中英

啟動Docker容器時如何運行php-fpm?

[英]How do I run php-fpm when I start docker container?

啟動Docker容器時如何自動運行php-fpm命令?

我有這個Dockerfile:

FROM composer:1.6.5 as build
WORKDIR /var/www
COPY . /var/www
RUN composer install

FROM php:7.2-fpm
USER root
RUN apt-get update && apt-get install -y \
    build-essential \
    mysql-client \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN apt-get update -y \
    && apt-get install -y nginx
RUN rm -rf /var/www/html
COPY --chown=www-data:www-data --from=build /var/www /var/www
COPY nginx.conf /etc/nginx/sites-enabled/default
EXPOSE 80

RUN service nginx restart
CMD ["nginx", "-g", "daemon off;"]

我知道我應該運行php-fpm因為當我訪問127.0.0.1:8080時,它不會顯示我的網頁。 但是,當我將ssh放入容器並運行php-fpm再次訪問127.0.0.1:8080它將顯示該網頁。

我應該在下面添加CMD ["php-fpm"]嗎? 在Dockerfile中有兩個CMD可以嗎?

它建議您創建一個start_service.sh腳本或其他。 在啟動容器時同時啟動php_fpm和nginx。

如果腳本是一個很好的主意,則應將其作為守護程序或在后台進行處理。 然后永遠等待。

#!/bin/bash
"start php_fpm"
"start_iginx"
sleep infinite

在Dockerfile中的CMD中,您只需調用腳本即可,而不是nginx。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM