<p>What you are looking for is a <code>sidecar</code> pattern where you run a container of your main application and a number of additional containers (one or more) in support of it. This is a well established pattern with orchestrators such as ECS but it's not possible to declare it with a docker compose syntax today. There is an <a href="https://github.com/docker/compose-cli/issues/1566" rel="nofollow noreferrer">open request</a> talking about this. Can I ask you to +1 it and add your commentary/request there? It would help Docker to sense demand for this feature. Thanks!</p>

CC BY-SA 4.0
2021-04-30T19:32:32.840Z
Will do, thank you!
Felix Eklöf
CC BY-SA 4.0
2021-04-30T11:26:58.400Z
2021-04-30T11:26:58.400Z
mreferre
<p>I'm using <a href="https://docs.docker.com/cloud/ecs-integration/" rel="nofollow noreferrer">this method</a> to deploy my docker-compose project to AWS ECS.</p>
<p>A simplified version of my docker-compose.yml looks like this:</p>
<pre class="lang-yaml prettyprint-override"><code>version: '3'

services:
  web:
    image: .dkr.ecr.eu-west-3.amazonaws.com/django:${IMAGE_TAG}
    build:
      context: .
      dockerfile: ./Dockerfile

  nginx:
    image: .dkr.ecr.eu-west-3.amazonaws.com/nginx:${IMAGE_TAG}
    build:
      context: .
      dockerfile: ./nginx.Dockerfile
    ports:
      - 80:80
    depends_on:
      - web
</code></pre>
<p>So, run <code>docker compose up</code> with my AWS ECS context and it works beautifully, cloud-formation creates all my resources and so on.</p>
<p>But, I can't figure out how to get these two services (web and nginx) to run in one task. Since they are in separate tasks at the moment it will create two instances of FARGATE or EC2 which is a bit overkill. I'd like two run the two containers on one instance but be able to scale up to more duplicate instances.</p>
<p>As stated in the link attached, I can modify the cloud-formation template to my liking, but something are limited to what I can modify. I don't think I can move that container service to another task since the image tag etc are created dynamically by <code>docker compose</code>.</p>
<p>My ECS cluster looks like this atm.
<a href="https://i.sstatic.net/lQ9c5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lQ9c5.png" alt="enter image description here" /></a></p>

<docker><amazon-ecs>
Docker compose to ECS, two services in one task
Felix Eklöf
# Docker compose to ECS, two services in one task

(Asked by: username_0 on 2021-04-30)

I'm using this method to deploy my docker-compose project to AWS ECS.
A simplified version of my docker-compose.yml looks like this:
version: '3'

services:
  web:
    image: .dkr.ecr.eu-west-3.amazonaws.com/django:${IMAGE_TAG}
    build:
      context: .
      dockerfile: ./Dockerfile

  nginx:
    image: .dkr.ecr.eu-west-3.amazonaws.com/nginx:${IMAGE_TAG}
    build:
      context: .
      dockerfile: ./nginx.Dockerfile
    ports:
      - 80:80
    depends_on:
      - web

So, run docker compose up with my AWS ECS context and it works beautifully, cloud-formation creates all my resources and so on.
But, I can't figure out how to get these two services (web and nginx) to run in one task. Since they are in separate tasks at the moment it will create two instances of FARGATE or EC2 which is a bit overkill. I'd like two run the two containers on one instance but be able to scale up to more duplicate instances.
As stated in the link attached, I can modify the cloud-formation template to my liking, but something are limited to what I can modify. I don't think I can move that container service to another task since the image tag etc are created dynamically by docker compose.
My ECS cluster looks like this atm.

**Tags:** docker, amazon-ecs


---

## 1 answers

### Answer by username_1 on 2021-04-30. Score: 1

What you are looking for is a `sidecar` pattern where you run a container of your main application and a number of additional containers (one or more) in support of it. This is a well established pattern with orchestrators such as ECS but it's not possible to declare it with a docker compose syntax today. There is an [open request](https://github.com/docker/compose-cli/issues/1566) talking about this. Can I ask you to +1 it and add your commentary/request there? It would help Docker to sense demand for this feature. Thanks!

> **Comments:**
> **username_0**: Will do, thank you!  

---

