Running a Drupal Site Using Docker Compose


In this assignment, we will run a Drupal site with postgres database. With docker-compose

Create a docker-compose.yml file,

touch docker-compose.yml

Our docker-compose.yml file should be as follows,

version: '3.1'
services:
  drupal:
    image: drupal:9.1.6
    ports:
      - '8080:80'
    volumes:
      - 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:
    image: postgres:13.2
    environment:
      - POSTGRES_DB=drupal
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
volumes:
  drupal-modules:
  drupal-profiles:
  drupal-sites:
  drupal-themes:

Now run the containers,

docker-compose up

After all the containers spined up, we can go to http://localhost:8080/. To set up, we have to select the postgres as it is using underline. Also, DB Name, DB User and DB Password should be same as the environments we passed through the docker-compose.yml file.

By default the drupal expect the database at localhost, but our database DNS name is postgres. From the Advance Options we have to also update the database host name.

To clean up all the containers along with the volumes, we can use

docker-compose down -v