Opinion: manage staging and production envs on a same server

Hi everyone!

I just discovered Traefik some days ago and I managed to use it in my docker-compose.yaml file to “orchestrate” all my services (db, backend, frontend, redis, grafana tools, traefik, …). Now I have a working setup, I’m thinking about how to organize and deploy it to have both production and staging environments on a same server (because my company only provides me a single server).

After some thinking, I think I have 2 solutions:

  1. Consider that my docker-compose.yaml file represents a full environment and I deploy it 2 times, one for production, one for staging. Each traefik instances listen to different ports (like 80/443 for prod, 8080/8043 for staging) and I use an nginx instance on the server to route to the right environment according to the domain name (like domain.com for prod, staging.domain.com for staging).
  2. Optimize the management of my containers by developing the infra containers only once (db, traefik, redis, …) and deploying the app 2 times. In this case, I could have 2 different docker networks ‘prod-network’ and ‘staging-network’.

I like the option (1) because it cleary separates both environments and if I want to test some upgrade of the infra part, I can safely do it in the staging env first, and then update the prod env. But several containers like the db are duplicated which is not so efficient.

I like the option (2) for its efficiency but it looks more complicated to manage, with a risk of conflicts/interference between both environments.

As I have not a lot of experiences in term of devops and I’m solo dev for this project, I would really appreciate your opinions about that. You would probably see some advantages/drawbacks for these 2 solutions that were not clear for me.

Thanks!

Remy

I think there is no real best practice, it always depends on your specific use case.

We use both. Re-use proxy and databases for a system running on bare metal, just add a new app service. Most components separate for systems using cloud instances, everything is created with scripts. With everything separate, it's of course easier to test upgrades across all components (proxy, service, database).

Hi bluepuma77!

Thank you for your reply!

Yes, I’m going to separate everything as my apps are not so heavy. At the end, I will also be able to shutdown the staging environment without impacting the prod environment.