0

I have this Dockerfile based on php-fpm

FROM php:7.1-fpm

RUN apt-get -y update && apt-get -y upgrade

# Basics
RUN apt-get -y install vim nano git curl cron zsh

# www-data user
RUN usermod -u 1000 www-data

RUN apt-get update \
    && apt-get install -y nginx \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
    && echo "daemon off;" >> /etc/nginx/nginx.conf

ADD default.conf /etc/nginx/sites-available/default

ADD . /var/www
WORKDIR /var/www

EXPOSE 80 9000
CMD ["nginx"]

I have installed nginx in this image and added configuration: default.conf

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www;
    index index.html index.htm index.php;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
}

This can load very well a html file but I don't know how to load a php file when I'm using a based php image.

I don't find the php socket to use fast cgi mode in this php-fpm image.

With a separetad php-fpm container I'll manage it that way:

location ~ ^/(index)\.php(/|$) {
        fastcgi_pass php-fpm:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param HTTPS off;
    }

But I want to use one single container. How can I do it? How can I change this line?

fastcgi_pass php-fpm:9000;

3
  • "But I want to use one single container." -- why is this the case? The current best practice in the Docker community is to split this sort of thing out. What problem are you running into by following that practice? Commented Nov 9, 2017 at 16:07
  • I know but I have to deploy to aws in one single container. No choice Commented Nov 9, 2017 at 16:26
  • Why no choice? Can you elaborate? Commented Nov 9, 2017 at 16:27

2 Answers 2

1

There are several ways,

  1. put php and nginx command in a script, say run.sh, then CMD run.sh.
  2. use process manager like supervisord
Sign up to request clarification or add additional context in comments.

1 Comment

My problem is more about how to replace this line fastcgi_pass php-fpm:9000;
0

You can use existed PHP-FPM +NGINX container. Or you can look at Container's dockerfile it can provide some help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.