Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

A unique docker-compose.yml file for sail (dev) and docker (prod) ?

Hello,

For 6 months I'm using sail for a Laravel / VueJS application with other services like RabbitMQ, soketi, ... I have added them in the docker-compose.yml file generated to be used with sail.

But for production, I have created my own docker-compose.yml file to use the application with all the needed services and sure with Nginx, PHP, ...

I think that sail is very uncomfortable because it seems impossible to have exactly the same docker-compose.yml file in development (using sail) and in production (without sail).

So what is the real benefit of sail ? For the moment it just adds complexicity because I have to handle 2 different docker configurations (dev and prod).

I thought about having one unique docker-compose.yml for both dev and prod, which would have more sense, but that means to not use sail in development.

Sure it's not so difficult to copy / paste the docker configuraton from on to the other configuration file. But it has no sense to duplicate this configuration.

So what is the solution ?

Perhaps I don't have understood well the real usage of sail ? Or perhaps it's really possible to have one unique docker-compose.yml and I don't know how to do ?

Has anybody already had such a problem ? What was your solution ?

Thanks a lot for sharing your experience with sail and docker.

V

0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

To address your concern about managing different docker-compose.yml files for development and production environments, you can indeed streamline the process by using a single docker-compose.yml file with environment-specific overrides. This approach allows you to maintain a base configuration and apply environment-specific settings as needed.

Here's a step-by-step solution:

  1. Create a Base docker-compose.yml File: This file will contain the common configuration for both development and production environments.

  2. Create an Override File for Development (docker-compose.override.yml): This file will contain the development-specific configuration. Docker Compose automatically uses this file to override the base configuration when you run docker-compose up.

    version: '3.8'
    
    services:
      app:
        environment:
          - APP_ENV=development
        volumes:
          - .:/var/www/html
          - ./sail:/etc/sail
        networks:
          - app-network
    
      web:
        ports:
          - "8080:80"
    
  3. Create an Override File for Production (docker-compose.prod.yml): This file will contain the production-specific configuration. You can specify this file explicitly when running Docker Compose commands in production.

    version: '3.8'
    
    services:
      app:
        environment:
          - APP_ENV=production
        volumes:
          - .:/var/www/html
        networks:
          - app-network
    
      web:
        ports:
          - "80:80"
    
  4. Running Docker Compose:

    • For development, simply run:

      docker-compose up
      

      Docker Compose will automatically use docker-compose.yml and docker-compose.override.yml.

    • For production, run:

      docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
      

      This command explicitly specifies the base and production override files.

By using this approach, you can maintain a single base configuration and apply environment-specific settings as needed, reducing duplication and complexity. This method leverages Docker Compose's built-in support for multiple configuration files, making it easier to manage different environments.

1 like
vincent15000's avatar

AI's response seems to be interesting.

But I'd like to have also real humans responses to share ideas. ;)

I have followed the series on docker here on Laracast, great series. But it doesn't speak about sail. And the folder architecture is to put the Laravel code in a src folder.

...
nginx // folder with the nginx configuration files
nginx.dockerfile // dockerfile for nginx
php.dockerfile // dockerfile for php
src // source folder for the Laravel application
...

In this case the Laravel application is separate from the other services, which sounds good.

But with the AI suggestion, the Laravel application will be in the same folder as the other services, which is less clean.

app
nginx // folder with the nginx configuration files
storage
resources
nginx.dockerfile // dockerfile for nginx
php.dockerfile // dockerfile for php

So the idea would perhaps be to move all what is not directly Laravel in a docker folder.

app
docker
	nginx // folder with the nginx configuration files
	nginx.dockerfile // dockerfile for nginx
	php.dockerfile // dockerfile for php
storage
resources

What do you think about that ?

Please or to participate in this conversation.