Docker Community Forums

Share and learn in the Docker community.

What is the proper way to deploy Symfony + nginx?

I have a stack in a swarm. It’s is Symfony + nginx. I implement it like both services can see each other data through a shared volume called app . The problem is when I change some data in the php image and I want to re-deploy the stack then I need to manually remove a stack and remove the app volume so that the app volume could be populated by a new php container.
Docker-compose:

version: '3.7'

volumes:
  app:

x-op-deploy: &deploy
  replicas: 1
  restart_policy:
     condition: on-failure
  placement:
     constraints: [node1]

x-php: &common-php-container
  image: someSymfonyImage
  volumes:
    - app:/var/www/app # the Symfony image has a workdir on this path
  deploy:
     <<: *deploy

services:

  php_fpm:
    <<: *common-php-container
    
  rest_server:
    image: nginx
    ports:
      - "8080:80"
    volumes:
      - app:/var/www/app
    command: '/bin/sh -c ''while :; do sleep 12h & wait $${!}; nginx -s reload; done & nginx -g "daemon off;"'''
    deploy:
       <<: *deploy

A snippet from nginx config:

...
    location ~ ^/index\.php(/|$) {
        fastcgi_pass php_fpm:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
...

Nginx Dockerfile:

FROM nginx

ADD docker/nginx/default.conf /etc/nginx/conf.d/default.conf

WORKDIR /var/www/app

What is the proper way to deploy Symfony + nginx? Any chanse I do this without copying data from a php image to a nginx image or without any binding to a persisten host volume where I preliminarily should put data?