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 Fletcher08 Apr 2025
How smart blocking protects your digital infrastructure
Across every industry, the operational risks of cyber threats are escalating. Automated bots, denial-of-service attacks and vulnerability scanners are increasingly common. For businesses operating in Australia and globally, implementing resilient, proactive security measures is essential to ensure...
Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...