Hello all
im trying to find a way to run 2 Drupal containers using a docker compose on a single machine. I am currently having a problem to ‘bind’ the each Drupal storage into a separate location in MySQL.
Here’s the YAML file for Docker Compose:
---
version: '3'
services:
drupal:
build: ./
image: geerlingguy/drupal:latest
environment:
DRUPAL_DATABASE_HOST: drupal-mysql
DRUPAL_DATABASE_PORT: 3306
DRUPAL_DATABASE_NAME: drupal
DRUPAL_DATABASE_USERNAME: drupal
DRUPAL_DATABASE_PASSWORD: drupal
# Generate a salt with: `php -r "echo bin2hex(random_bytes(25));"`
DRUPAL_HASH_SALT: db0de8a1556aa5348f87cfc950cd2c9641713d46e9412c8b05
ports:
#assign random port on the host
- "80"
depends_on:
- mysql
restart: always
# new
working_dir: /var/www/html
# Uncomment the volumes line and set to the local path of your Drupal
# installation, if you need to work with a local codebase.
volumes:
# - ~/Sites/drupal-container:/var/www/html:rw,delegated
- /Sites/drupal-container:/var/www/html:rw,delegated
drupal2:
build: ./
image: geerlingguy/drupal:latest
environment:
DRUPAL_DATABASE_HOST: drupal-mysql
DRUPAL_DATABASE_PORT: 3306
DRUPAL_DATABASE_NAME: drupal
DRUPAL_DATABASE_USERNAME: drupal
DRUPAL_DATABASE_PASSWORD: drupal
# Generate a salt with: `php -r "echo bin2hex(random_bytes(25));"`
DRUPAL_HASH_SALT: db0de8a1556aa5348f87cfc950cd2c9641713d46e9412c8b05
ports:
#assign random port on the host
- "80"
depends_on:
- mysql
restart: always
working_dir: /var/www/html
volumes:
- /Sites/drupal-container2:/var/www/html:rw,delegated
mysql:
image: mysql:5.7
container_name: drupal-mysql
# new
volumes:
- /Sites/drupal-container:/var/lib/mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
ports:
- "3306:3306"
networks:
# Define the default network
# Services will use this automatically without having a networks key
default:
external:
name: macvlan_net
```
FYI the network named macvlan_net is defined manually outside of the YAML file. (this allows me to access the Drupal container using IP address)
Problem:
when I run docker-compose up, I get 2 Drupal containers:
Drupal 1 - 132.177.14.1
Drupal 2 - 132.177.14.2
but once i run through the initial setup on Drupal 1, Drupal 2 seems to be mirroring the setup that I made also.
Expected result:
I should be greeted by the initial setup when visiting Drupal 2.