从php fpm image自动启动Nginx

时间:2018-10-12 11:58:01

标签: docker nginx

我有以下Dockerfile

FROM php:7.2-fpm

LABEL maintainer="youri@smilinggents.nl"

RUN apt-get update && \
    apt-get install -y nginx git zip

COPY default.conf /etc/nginx/conf.d/default.conf

RUN apt-get update && \
    apt-get install -y libpng-dev libxml2-dev libcurl3-dev libcurl4-openssl-dev && \
    docker-php-ext-install gd && \
    docker-php-ext-install soap && \
    docker-php-ext-install pdo_mysql && \
    docker-php-ext-install intl && \
    docker-php-ext-install zip

RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer

WORKDIR /var/www/pidz/

RUN mkdir ./var/
COPY ./app app
COPY ./bin bin
COPY ./src src
COPY ./web web
COPY ./composer.json composer.json
COPY ./composer.lock composer.lock

ARG SSH_PRIVATE_KEY
# some ssh stuff I perform

RUN export SYMFONY_ENV=staging && \
    composer install

EXPOSE 80

当我构建Dockerfile时

docker build . --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)"

并运行图像

docker run -p 80:80 <image>

Nginx没有运行,但是当我在容器Nginx中运行nginx

如何使Nginx自动启动?

1 个答案:

答案 0 :(得分:1)

因为您没有启动nginx。

docker run -p 80:80 <image> -d nginx

或者您可以在Dockerfile中添加CMD ["/usr/sbin/nginx", "-g", "daemon off;"]官方Dockerfile结尾,然后在您运行映像时它将自动启动