I just did that last week for a project, using sail for the dev environment and pure docker for the production environment.
I have done it with 3 docker compose files :
-
docker-compose.yml : is the base docker compose file for the common configurations for dev and prod
-
docker-compose.override.yml : is the docker compose file for the specific dev configurations
-
docker-compose.prod.yml : is the docker compose file for the specitif prod configurations
When you run : sail up, it will automatically merge docker-compose.yml and docker-compose.override.yml.
In docker-compose.override.yml, you can add new configurations and/or replace any existing configuration from the docker-compose.yml base file. For example rename a container.
To run the project in production, you need to run this command.
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
It will merge both docker-compose.yml and docker-compose.override.yml files.
You can even check the resulting configuration file by running this command.
docker-compose -f docker-compose.yml -f docker-compose.prod.yml config
In docker-compose.prod.yml, you can add new configurations and/or replace any existing configuration from the docker-compose.yml base file. For example rename a container.
The advantage is to use exactly the same environment in development and in production.