Docker-compose and production/staging environments

Here is my scenario:

I have nginx, mariadb, certbot, and a production/staging backend that I want to run on a single VM instance all in their own containers.

I want to integrate this with my CI/CD system.

I want to be able to selectively build/deploy the staging or production container based on what image is being used. But staging and production should both use the same nginx reverse proxy, mariadb, and certbot instances.

I was able to make this happen just using docker run but I'm struggling to understand how to make this work with docker-compose. Mostly because I can't find a single example that covers this scenario. Every example I come across is either trying to show me how to implement literal microservice hell, where every container is deployed for every build. Or it's trying to show me how to deploy nginx, backend, database, etc, but there's no staging or production. So no services are being shared between containers and there's not really any staging or production separation happening.

I know how to set the CI/CD itself up and what commands I need to run to bring up a docker-compose stack. I know you can layer docker compose files. But I don't know how to make this work the way I need it to work.

submitted by /u/vicata_heth
[link] [comments]
Source: Reddit