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 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...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...
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...