Skip to main content

Running Docker

Dangerous word... I'm assuming that Docker is installed.  Don't know how to check?  Using Terminal (I prefer iTerm2), run the following command

docker -D info

 

The set-up

Go to your project directory, and create a docker folder and a “docker-compose.yml” file:

mkdir/Users/{your_name}/Sites/{your_directory}
cd /Users/{your_name}/Sites/{your_directory}
mkdir docker
cd docker
vim docker-compose.yml

Copy following code and add it in to the docker-compse.yml file:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
    links:
      - php
      - database
    volumes:
      - ../src:/var/www/html

  php:
    image: php:8.1-fpm
    ports:
       - "9000:9000"
    volumes:
      - ../src:/var/www/html

  database:
    image: mariadb:latest
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_USER=dbuser
      - MYSQL_PASSWORD=root
      - MYSQL_DATABASE=proxy
    ports:
      - "3306:3306"
    volumes:
      - "/Users/{your_name}/Sites/web-proxy:/var/lib/mysql"

 

Adjust the following variables from the above command:

MySQL root password: root
Database name: proxy
MySQL user: dbuser
MySQL password: root

 

There are now three containers:

  • Web container for Nginx latest version, with mapping port 80:80 (the post can be changed to another one if your 80 is used, 84:80, 8083:80 are examples).  If you have issues with the port being already in use, then errors like below will come up.
  • PHP container for the php with the FastCGI Process Manager (FPM).
  • Database container for MariaDB latest version, it’s required to specify MySQL environment variable.

 

Error bind: address already in use

When attempting the above command did you receive the following error?

docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: address already in use.

 

You can try port 8080.

Error: port already allocated

docker: Error response from daemon: driver failed programming external connectivity on endpoint drupal9 ({HASH}): Bind for 0.0.0.0:8080 failed: port is already allocated.

 

You can try port 8083.

Success!  You will need to play around here to get a free port.  Or you can query the ports for their status.

 

Installing Drupal 9.x

To install Drupal, use the following command

composer create-project drupal-composer/drupal-project:9.x-dev {some-dir} --no-interaction

Change {some-dir} to the directory that you want to install.  If you want to install on the directory that you are currently in, use ./

composer create-project drupal-composer/drupal-project:9.x-dev ./ --no-interaction

 

Related articles

Andrew Fletcher20 Feb 2025
Handling duplicate records in Drupal
Duplicate records in Drupal can cause significant issues, particularly when they lead to integrity constraint violations in the database. These errors often occur due to duplicate UUIDs in the `node` table, which can result from programmatic imports, migrations, or unintended database...
Andrew Fletcher17 Feb 2025
The overlooked challenge of migration updates in Drupal projects
When working on Drupal migrations, developers often assume that adding a new field to the process section will seamlessly update existing content. However, unless explicitly handled, Drupal’s migration system does not automatically apply changes to previously migrated records. This oversight can...
Andrew Fletcher11 Feb 2025
Webpack build process and theme automation improvements
The Drupal theme configuration has undergone recent changes made to the Webpack configuration, SCSS and JavaScript handling, and automation of updates to the orw.libraries.yml file in the custom Drupal theme. These changes are designed to improve the build process, enhance maintainability, and...