skip to Main Content

Most of the times I see in the docker-compose.yml two separated services for ngnix and php, like this:

version: '3.3'

services:
  php:
    image: php
    ports:
      - "127.0.0.1:8000:8000"
    volumes:
      - ".:/code_folder"
    networks:
      - default

  ngnix:
    image: ngnix
    ports:
      - "127.0.0.1:80:80"
    volumes:
      - ".:/code_folder"
    networks:
      - default

I would assume there must be a single image having ngnix and php together but it’s not a commonly used approach.
Another question is:
how does it works, since those will be separated containers, both mounting the same code base?

2

Answers


  1. Because each container should run a single service. The design pattern should be it runs a service then when it completes it stops itself. It just happens that nginx and php need to continuously listen and therefor don’t stop naturally

    Login or Signup to reply.
  2. You’re missing mapping your Nginx configuration file which is what makes the whole difference.

    The configuration file specifies that all requests for PHP files should be passed on to the PHP container. All non-PHP files are served directly by the Nginx container.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search