Docker series (Part 15): Build a compose file for multi container project
Tags: docker
Published: 2022-07-11 14:44:27


The tasks we will complete in this blog are:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/csz2e2mmp4frpwtl2ms7.png)
 
This time we will use compose-assignment-2 folder from [this repository](https://github.com/bretfisher/udemy-docker-mastery)
We have docker-compose.yml file here

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/80dzbdu2rc0qn83525ya.png)
 We will checkout [this repo](https://hub.docker.com/_/drupal) in docker hub .

The docker-compose.yml will look like this
```
services:

  drupal:
    image: custom-drupal #image name (we have created a custo image in Dockerfile and used it here)
    build: .
    ports:
      - "8080:80" #setting ports checked from documentation or inspect of image
    volumes: # added volumes from documentation https://hub.docker.com/_/drupal
      - drupal-modules:/var/www/html/modules
      - drupal-profiles:/var/www/html/profiles       
      - drupal-sites:/var/www/html/sites      
      - drupal-themes:/var/www/html/themes
 
  postgres: # another container
    image: postgres #image used
    environment: #environmental variables
      - POSTGRES_PASSWORD=mypasswd #setting password
    volumes: #setting volume for thhs
      - drupal-data:/var/lib/postgresql/data

volumes: #mentioning all of the volumes names created within containers
  drupal-data:
  drupal-modules:
  drupal-profiles:
  drupal-sites:
  drupal-themes:

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/szj87aav3431thknw9tk.png)
 
Here we created a custom drupal image and created that on the "Dockerfile"
So the dockerfile will have:

```
FROM drupal:8.8.2

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    git \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html/themes

RUN git clone --branch 8.x-3.x --single-branch --depth 1 https://git.drupalcode.org/project/bootstrap.git \
    && chown -R www-data:www-data bootstrap

WORKDIR /var/www/html

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqybupy6bpfvd9rl9jxq.png)
now save them and go to terminal and run

```
docker-compose up
```

This will run the docker-compose.yml file

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xglxsz2ca9qwfzbkqyc.png)

Now , go to web browser and type "localhost:8080"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/55xvu1se4m4v8v8pzf6z.png)
 You will see this.

Your terminal might look like this

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gljpp7jq5m76vpxcewea.png)
 
NOW, press save & continue

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qmox1ywbcuiah4qw1d81.png)
Standard-> save & continue

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbl5f6xnojl5dybkzq74.png)
 Set the database type to Postgres


You can go to postgres repo in [docker hub](https://hub.docker.com/_/postgres)  and see how default database works.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iahjx1ge5pk7ir7u3h4w.png)

Now we will set some default information:


here we used the password we did set in the .yml file


from the advanced options, set the local host to service name which is "postgres" and press Save & continue

 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ai5cnfj5a155vm58kyb.png)
 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ltkrz52lt5t2xo2ujh1.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5kssrktodajje46i9wjc.png)
Set the other details and you are good to go !



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/op9xmb9pyjaxhebnsw22.png)

<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">