# Aws and Jenkins =Docker Compose

### Using Docker Compose for Deployment

**docker compose use yaml file**&#x20;

![](https://604868167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQ9IWUW0VjkKLJPOeTIP3%2Fuploads%2FYrPXRkgo9ndhpwt5Y85p%2Fimage.png?alt=media\&token=c30db2f8-38bc-4427-a9b8-3f0b7e108b20)

{% hint style="info" %}
**Just started 1 Docker Container = Docker run**

Small application with multiple services would start with Docker Compose

**docker-compose command**&#x20;

**docker-compose -f docker-compose.yaml up**
{% endhint %}

### Install Docker Compose

* [ ] you must enter aws account in comand line then you must download docker compose
* [ ] **sudo curl -L "<https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname> -s)-$(uname -m)" -o /usr/local/bin/docker-compose**
* [ ] **sudo chmod +x /usr/local/bin/docker-compose**
* [ ] **docker-compose --version**

### **Create Docker Compose FIle**

{% embed url="<https://gitlab.com/nanuchi/java-maven-app/-/blob/feature/jenkinsfile-sshagent/docker-compose.yaml>" %}

```
version: '3.8'
services:
    java-maven-app:
      image: ${IMAGE}
      ports:
        - 8080:8080
    postgres:
      image: postgres:13
      ports:
        - 5432:5432
      environment:
        - POSTGRES_PASSWORD=my-pwd
```

![\]](https://604868167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQ9IWUW0VjkKLJPOeTIP3%2Fuploads%2FENMyqE2Tuoama5Kz7mRr%2Fimage.png?alt=media\&token=4975ce4f-9243-4acd-8dc0-8d940703c6c8)

![](https://604868167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQ9IWUW0VjkKLJPOeTIP3%2Fuploads%2FNaRYRD5NuWOpwvku6bVJ%2Fimage.png?alt=media\&token=435566eb-2946-46f8-a185-2528fd0423e2)

### Make Jenkinsfile adjustments

* [ ] we need the docker-compose.yaml file on EC2 instance
* [ ] **docker-compose -f docker-compose.yaml up**
* [ ] **in the Jenkinsfile add**&#x20;
* [ ] **sh "scp docker-compose.yaml ec2-user\@aws public ip\:/home/ec2-user"**
* [ ] **def dockerComposeCmd = "Docker-compose -f docker-compose.yaml up --detach"**

![](https://604868167-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQ9IWUW0VjkKLJPOeTIP3%2Fuploads%2FVpRQmW0az6oOv7fpmUKp%2Fimage.png?alt=media\&token=77117d66-be64-4941-b4c1-760bf3071308)

{% embed url="<https://gitlab.com/nanuchi/java-maven-app/-/blob/feature/jenkinsfile-sshagent/Jenkinsfile>" %}
