Docker Community Forums

Share and learn in the Docker community.

Multiple applications in one compose-file

Good day dear community

I don’t know if I’m in the right place here or if I should post this question in the Nextcloud community.

I am currently more and more involved with Docker and Docker Compose and find this simply ingenious. However, I always hit a wall with a question/task and need some expert knowledge.

I have created a Docker Compose file which includes the following things…Two Nextclouds, mariadb, nginx proxy manager and mariadb-aria for nginx proxy manager. Starting the compose file works without any problems and errors but the database always creates only one created database. Although I have actually declared this. My compose file looks like this.

version: '3'

volumes:
  nextcloud-data-X:
  nextcloud-data-Y:
  nextcloud-db:
  npm-data:
  npm-ssl:
  npm-db:

networks:
  frontend:
  backend:

services:

  nextcloud-app-X:
    image: nextcloud:stable
    restart: always
    volumes:
      - nextcloud-data-X:/var/www/html
    environment:
      - MYSQL_PASSWORD=Cropped
      - MYSQL_DATABASE=nextcloudsystemX
      - MYSQL_USER=nextcloudX
      - MYSQL_HOST=nextcloud-db
    networks:
      - frontend
      - backend
	depends_on:
	  - nextcloud-db:

  nextcloud-app-Y:
    image: nextcloud:stable
    restart: always
    volumes:
      - nextcloud-data-Y:/var/www/html
    environment:
      - MYSQL_PASSWORD=Cropped
      - MYSQL_DATABASE=nextcloudY
      - MYSQL_USER=nextcloudY
      - MYSQL_HOST=nextcloud-db
    networks:
      - frontend
      - backend
	depends_on:
	  - nextcloud-db:

  nextcloud-db:
    image: mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - nextcloud-db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=Cropped
      - MYSQL_PASSWORD=Cropped
      - MYSQL_DATABASE=nextcloudX
      - MYSQL_DATABASE=nextcloudY
      - MYSQL_USER=nextcloudX
      - MYSQL_USER=nextcloudY
    networks:
      - backend

  npm-app:
    image: jc21/nginx-proxy-manager:latest
    restart: always
    ports:
      - "80:80"
      - "81:81"
      - "443:443"
    environment:
      - DB_MYSQL_HOST=npm-db
      - DB_MYSQL_PORT=3306
      - DB_MYSQL_USER=npm
      - DB_MYSQL_PASSWORD=Cropped
      - DB_MYSQL_NAME=npm

    volumes:
      - npm-data:/data
      - npm-ssl:/etc/letsencrypt
    networks:
      - frontend
      - backend
	depends_on:
	  - npm-db

  npm-db:
    image: jc21/mariadb-aria:latest
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=Cropped
      - MYSQL_DATABASE=npm
      - MYSQL_USER=npm
      - MYSQL_PASSWORD=Cropped
    volumes:
      - npm-db:/var/lib/mysql
    networks:
      - backend

What am I doing wrong here or do I need to do right? As can be seen, the Nextcloud applications are supposed to create a DB in the specified MariaDB application, which means that Two databases must be created.

I thank you for the first time for your time and experience

Just think about it. You can’t define one variable multiple times. Those are just simple environment variables. Try to run this in a linux shell and see what happens:

MYSQL_DATABASE=nextcloudX
MYSQL_DATABASE=nextcloudY


echo $MYSQL_DATABASE

This syntax is very misleading:

environment:
  - MYSQL_DATABASE=nextcloudX
  - MYSQL_DATABASE=nextcloudY

I don’t understand why this is allowed. This is how I always do it:

environment:
  MYSQL_DATABASE: nextcloudX
  MYSQL_DATABASE: nextcloudY

Then the IDE can warn you the variable is duplicated.

It is your job to create databases. The fact that you use Docker and the container has an init script to kindly generate ONE database for you is just a little help for development.