DEV Community 👩‍💻👨‍💻

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Docker series (Part 15): Build a compose file for multi container project

The tasks we will complete in this blog are:
Image description

This time we will use compose-assignment-2 folder from this repository
We have docker-compose.yml file here

Image description
We will checkout this repo in docker hub .

The docker-compose.yml will look like this


    image: custom-drupal #image name (we have created a custo image in Dockerfile and used it here)
    build: .
      - "8080:80" #setting ports checked from documentation or inspect of image
    volumes: # added volumes from documentation
      - 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

Enter fullscreen mode Exit fullscreen mode

Image description

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 \
    && chown -R www-data:www-data bootstrap

WORKDIR /var/www/html

Enter fullscreen mode Exit fullscreen mode

Image description
now save them and go to terminal and run

docker-compose up
Enter fullscreen mode Exit fullscreen mode

This will run the docker-compose.yml file

Image description

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

Image description
You will see this.

Your terminal might look like this

Image description

NOW, press save & continue

Image description
Standard-> save & continue

Image description
Set the database type to Postgres

You can go to postgres repo in docker hub and see how default database works.

Image description

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

Image description

Image description
Set the other details and you are good to go !

Image description

Oldest comments (0)

18 Useful Github Repositories Every Developer Should Bookmark

18 Useful GitHub repositories every developer should bookmark: everything from learning resources and roadmaps to best practices, system designs, and tools.