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.ymlCopy 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-interactionChange {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