0

I have the following 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

When I build the Dockerfile

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

And run the image

docker run -p 80:80 <image>

Nginx is not running, but when I run nginx inside the container Nginx is started

How can I make Nginx starting automatically?

yooouuri
  • 2,578
  • 10
  • 32
  • 54

1 Answers1

1

Because you don't start the nginx.

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

or you can add CMD ["/usr/sbin/nginx", "-g", "daemon off;"] official Dockerfile end of the Dockerfile then when u run the image it will automatically will start

Ntwobike
  • 2,406
  • 1
  • 21
  • 27
  • `CMD` still stop the container, see: https://stackoverflow.com/a/42219138/2753579 – yooouuri Oct 12 '18 at 12:08
  • in the latter case, remember to put `daemon off;` into your nginx conf as not to fork to background, otherwise your container will just terminate after starting nginx. – joppich Oct 12 '18 at 12:09
  • @Ntwobike when I add `CMD ["/usr/sbin/nginx", "-g", "daemon off;"]`, php is not running anymore... – yooouuri Oct 12 '18 at 13:10