r/devops • u/aress1605 • Aug 12 '26
Architecture Deploying docker-compose.yml
Hello all. The circumstance I have working with is the following:
* I have an Apache2 PHP server that gets bundled as a Docker image in a CI process to ECR
* I have an infra repository with a docker-compose.yml that bundles the PHP Docker image to an Nginx image, alongside Nginx config like attaching TLS certs
When the CICD process deploys a release, it deploys a new EC2 with a given user data script to prop up the server. If I only had a Docker image, the user data would generally look like "Pull down ECR image and start image", however in this case I am spinning up a docker-compose.yml file.
How is this typically done? I suppose I *can* add a CI process to zip up the docker-compose.yml and related nginx config, however feels backwards? Is there a consensus with this?
If I am fundamentally misunderstanding something let me know, I'd say my only constraint is I'd like to solve this problem in a relatively cloud agnostic environment (so keeping EC2 as a VM, ECR as a registry, but excluding abstractions like Fargate or ECS)
Thanks!
View all comments
1
u/SeaworthinessHour233 DevOps Engineer & Educator Aug 12 '26
Here's one way you can achieve this.
Instead of figuring out how to get your
docker-compose.ymland Nginx configs onto a running server at boot time, you bake them into the machine image itself using a tool like HashiCorp Packer.Here is how that workflow looks in a CI/CD pipeline:
Your CI builds the new PHP Docker image and pushes it to ECR.
2. Bake the AMI:
Your CI triggers Packer. Packer temporarily spins up a base EC2 instance and runs a provisioner script (bash or Ansible) that:
2.1 Installs Docker and Docker Compose.
2.2 Copies your
docker-compose.ymland Nginx configuration directory directly into the instance (ex: to/opt/app).2.3 Authenticates to ECR and runs
docker compose pullto cache your newly built images right onto the disk.2.4 Sets up a simple
systemdservice to ensuredocker-compose up -druns on boot.3. Deploy:
Packer snapshots this instance into a new AMI. Your deployment step then updates your Auto Scaling Group or spins up a fresh EC2 instance using this exact AMI.
Pros:
Cons
It takes a little bit of upfront work to set up Packer with your pipeline.
There are other ways with different pros and cons that you can achieve the same.