When a service in the compose file exposes a port, a load balancer is being created and configured to distribute the traffic between all containers.
There are 2 types of Load Balancers that can be created. For a service exposing a non-http port/protocol, a __Network Load Balancer (NLB)__ is created. Services with http/https ports/protocols get an __Application Load Balancer (ALB)__.
There is only one load balancer created/configured for a Compose stack. If there are both http/non-http ports configured for services in a compose stack, an NLB is created.
The compose file below configured only the http port,therefore, on deployment it gets an ALB created.
```yaml
services:
app:
image: nginx
ports:
- 80:80
```
NLB is created for non-http port
```yaml
services:
app:
image: nginx
ports:
- 8080:8080
```
To use the http protocol with custom ports and get an ALB, use the `x-aws-protocol` port property.
```yaml
services:
test:
image: nginx
ports:
- target: 8080
x-aws-protocol: http
```
To re-use an external load balancer and avoid creating a dedicated one, set the top-level property `x-aws-loadbalancer` as below:
```yaml
x-aws-loadbalancer: "LoadBalancerName"
services:
app:
image: nginx
ports:
- 80:80
```
Similarly, an external `VPC` and `Cluster` can be reused:
```yaml
x-aws-vpc: "vpc-25435e"
x-aws-cluster: "ClusterName"
services:
app:
image: nginx
ports:
- 80:80
```
Keep in mind, that external resources are not managed as part of the compose stack's lifecycle.
## Volumes
```yaml
services:
app:
image: nginx
volumes:
- data:/test
volumes:
data:
```
To use of an external volume that has been previously created, set its id/ARN as the name:
When a service is configured with an image from a private repository on Docker Hub, make sure you have configured pull credentials correctly before deploying the Compose stack.
To create a pull credential, create a file with the following content:
```sh
$ cat creds.json
{
"username":"DockerHubID",
"password":"GeneratedHubTokenOrPassword"
}
```
To create the pull credential and retrieve the `ARN/ID` to use in the compose file run: