How can I automatically run php-fpm
command when I start the docker container?
I have this 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;"]
I know I should run php-fpm
because when I access 127.0.0.1:8080 it doesn't show my webpage. But when I ssh into the container and run php-fpm
then visit 127.0.0.1:8080 again it will show the webpage.
Should I add CMD ["php-fpm"]
below? Is it okay to have two CMD
in the Dockerfile?
It suggest that you create a start_service.sh script or whatever. to start both php_fpm and nginx when you start the container.
If the script its a good idea to both processes as daemons or in the background. And then just wait forever.
#!/bin/bash
"start php_fpm"
"start_iginx"
sleep infinite
In the CMD in the Dockerfile you just call your script instead of nginx.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.