Skip to content

Commit 3d49647

Browse files
authored
Merge pull request #11765 from gtardif/more-ecs-aci-docs
Adding more basic examples of compose files, and small updates on ECS services dependencies, service name resolution
2 parents 343f444 + 29bd2b0 commit 3d49647

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

engine/context/aci-integration.md

+28-6
Original file line numberDiff line numberDiff line change
@@ -177,27 +177,51 @@ Total CPUs reclaimed: 2.01, total memory reclaimed: 2.30 GB
177177

178178
## Exposing ports
179179

180-
Single containers and Compose applications can optionally expose ports. For single containers, this is done using the `--publish` (`-p`) flag of the `docker run` command and for Compose applications, you must specify exposed ports in the Compose file service definition.
180+
Single containers and Compose applications can optionally expose ports.
181+
For single containers, this is done using the `--publish` (`-p`) flag of the `docker run` command : `docker run -p 80:80 nginx`.
182+
183+
For Compose applications, you must specify exposed ports in the Compose file service definition:
184+
185+
```yaml
186+
services:
187+
nginx:
188+
image: nginx
189+
ports:
190+
- "80:80"
191+
```
192+
181193
182194
> **Note**
183195
>
184196
> ACI does not allow port mapping (that is, changing port number while exposing port). Therefore, the source and target ports must be the same when deploying to ACI.
185197
>
186-
>
187-
> All containers in the same Compose application are deployed in the same ACI container group. Containers in the same Compose application cannot expose the same port when deployed to ACI.
198+
> All containers in the same Compose application are deployed in the same ACI container group. Different containers in the same Compose application cannot expose the same port when deployed to ACI.
188199
189200
By default, when exposing ports for your application, a random public IP address is associated with the container group supporting the deployed application (single container or Compose application).
190201
This IP address can be obtained when listing containers with `docker ps` or using `docker inspect`.
191202

192203
### DNS label name
193204

194205
In addition to exposing ports on a random IP address, you can specify a DNS label name to expose your application on an FQDN of the form: `<NAME>.region.azurecontainer.io`.
195-
You can set this name with the `--domainname` flag when performing a `docker run`, or by using the `domainname` field in the Compose file when performing a `docker compose up`.
206+
207+
You can set this name with the `--domainname` flag when performing a `docker run`, or by using the `domainname` field in the Compose file when performing a `docker compose up`:
208+
209+
```yaml
210+
services:
211+
nginx:
212+
image: nginx
213+
domainname: "myapp"
214+
ports:
215+
- "80:80"
216+
```
217+
196218

197219
> **Note**
198220
>
199221
> The domain of a Compose application can only be set once, if you specify the
200222
> `domainname` for several services, the value must be identical.
223+
>
224+
> The FQDN `<DOMAINNAME>.region.azurecontainer.io` must be available.
201225

202226
## Using Azure file share as volumes in ACI containers
203227

@@ -328,8 +352,6 @@ services:
328352
healthcheck:
329353
test: ["CMD", "curl", "-f", "http://localhost:80"]
330354
interval: 10s
331-
timeout: 2s
332-
start_period: 40s
333355
```
334356

335357
## Private Docker Hub images and using the Azure Container Registry

engine/context/ecs-integration.md

+33-5
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,29 @@ services:
149149
150150
> **Note**
151151
>
152-
> If you set the Compose file version to 3.8 or later, you can use the same Compose file for local deployment using `docker-compose`. Custom extensions will be ignored in this case.
152+
> If you set the Compose file version to 3.8 or later, you can use the same Compose file for local deployment using `docker-compose`. Custom ECS extensions will be ignored in this case.
153153

154154
## Service discovery
155155

156-
Service-to-service communication is implemented by the [Security Groups](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html){: target="_blank" rel="noopener" class="_"} rules, allowing services sharing a common Compose file “network” to communicate together. This allows individual services to run with distinct constraints (memory, cpu) and replication rules. However, it comes with a constraint that Docker images have to handle service discovery and wait for dependent services to be available.
156+
Service-to-service communication is implemented transparently by default, so you can deploy your Compose applications with multiple interconnected services without changing the compose file between local and ECS deployment. Individual services can run with distinct constraints (memory, cpu) and replication rules.
157157

158158
### Service names
159159

160-
Services are registered by the Docker Compose CLI on [AWS Cloud Map](https://docs.aws.amazon.com/cloud-map/latest/dg/what-is-cloud-map.html){: target="_blank" rel="noopener" class="_"} during application deployment. They are declared as fully qualified domain names of the form: `<service>.<compose_project_name>.local`. Services can retrieve their dependencies using this fully qualified name, or can just use a short service name (as they do with docker-compose).
160+
Services are registered automatically by the Docker Compose CLI on [AWS Cloud Map](https://docs.aws.amazon.com/cloud-map/latest/dg/what-is-cloud-map.html){: target="_blank" rel="noopener" class="_"} during application deployment. They are declared as fully qualified domain names of the form: `<service>.<compose_project_name>.local`.
161+
162+
Services can retrieve their dependencies using Compose service names (as they do when deploying locally with docker-compose), or optionally use the fully qualified names.
161163

162164
### Dependent service startup time and DNS resolution
163165

164-
Services get concurrently scheduled on ECS when a Compose file is deployed. AWS Cloud Map introduces an initial delay for DNS service to be able to resolve your services domain names. As a result, your code needs to be adjusted to support this delay by waiting for dependent services to be ready, or by adding a wait-script as the entrypoint to your Docker image, as documented in [Control startup order](https://docs.docker.com/compose/startup-order/).
166+
Services get concurrently scheduled on ECS when a Compose file is deployed. AWS Cloud Map introduces an initial delay for DNS service to be able to resolve your services domain names. Your code needs to support this delay by waiting for dependent services to be ready, or by adding a wait-script as the entrypoint to your Docker image, as documented in [Control startup order](https://docs.docker.com/compose/startup-order/).
167+
Note this need to wait for dependent services in your Compose application also exists when deploying locally with docker-compose, but the delay is typically shorter. Issues might become more visible when deploying to ECS if services do not wait for their dependencies to be available.
165168

166169
Alternatively, you can use the [depends_on](https://github.com/compose-spec/compose-spec/blob/master/spec.md#depends_on){: target="_blank" rel="noopener" class="_"} feature of the Compose file format. By doing this, dependent service will be created first, and application deployment will wait for it to be up and running before starting the creation of the dependent services.
167170

171+
### Service isolation
172+
173+
Service isolation is implemented by the [Security Groups](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html){: target="_blank" rel="noopener" class="_"} rules, allowing services sharing a common Compose file “network” to communicate together using their Compose service names.
174+
168175
## Volumes
169176

170177
ECS integration supports volume management based on Amazon Elastic File System (Amazon EFS).
@@ -279,6 +286,15 @@ value `*` to get all keys bound in your container.
279286

280287
## Auto scaling
281288

289+
Scaling service static information (non auto-scaling) can be specified using the normal Compose syntax:
290+
291+
```yaml
292+
services:
293+
foo:
294+
deploy:
295+
replicas: 3
296+
```
297+
282298
The Compose file model does not define any attributes to declare auto-scaling conditions.
283299
Therefore, we rely on `x-aws-autoscaling` custom extension to define the auto-scaling range, as
284300
well as cpu _or_ memory to define target metric, expressed as resource usage percent.
@@ -336,7 +352,19 @@ The Docker Compose CLI relies on [Amazon CloudFormation](https://docs.aws.amazon
336352

337353
## Using existing AWS network resources
338354

339-
By default, the Docker Compose CLI creates an ECS cluster for your Compose application, a Security Group per network in your Compose file on your AWS account’s default VPC, and a LoadBalancer to route traffic to your services. If your AWS account does not have [permissions](https://github.com/docker/ecs-plugin/blob/master/docs/requirements.md#permissions){: target="_blank" rel="noopener" class="_"} to create such resources, or if you want to manage these yourself, you can use the following custom Compose extensions:
355+
By default, the Docker Compose CLI creates an ECS cluster for your Compose application, a Security Group per network in your Compose file on your AWS account’s default VPC, and a LoadBalancer to route traffic to your services.
356+
357+
With the following basic compose file, the Docker Compose CLI will automatically create these ECS constructs including the load balancer to route traffic to the exposed port 80.
358+
359+
```yaml
360+
services:
361+
nginx:
362+
image: nginx
363+
ports:
364+
- "80:80"
365+
```
366+
367+
If your AWS account does not have [permissions](https://github.com/docker/ecs-plugin/blob/master/docs/requirements.md#permissions){: target="_blank" rel="noopener" class="_"} to create such resources, or if you want to manage these yourself, you can use the following custom Compose extensions:
340368

341369
- Use `x-aws-cluster` as a top-level element in your Compose file to set the ARN
342370
of an ECS cluster when deploying a Compose application. Otherwise, a

0 commit comments

Comments
 (0)