How does one go about actually configuring one database per service?

I've been trying to launch both Nextcloud and a WordPress installation on the same VPS using docker-compose and a Caddy reverse proxy.

I have three compose files: docker-compose which launches Caddy, wordpress-compose which launches wordpress and MySQL, and nextcloud-compose which launches Nextcloud and MariaDB.

I have a .env file with the various passwords and such defined. All of this sits in /home/$USER/docker/caddy. The various compose files are listed below. I have a few questions that I am hoping you can help me with.

1) Is it a best practice to have each of the compose files in the same directory? Is it required for Caddy to function properly.

2) Is it a best practice to have required services placed together in one compose file (i.e. the nextcloud and wordpress separate, but the wordpress SQL together)?

3) After reviewing this thread, I want to configure separate databases for each of my services. What is the best way to go about actually doing that?

As of right now I have nextcloud working properly, but wordpress has a "Error establishing a database connection" error. I greatly appreciate any help I can get. As you can likely tell, I am a novice at this!

Docker-Compose:

version: "3.8" services: caddy: image: caddy container_name: caddy hostname: caddy restart: unless-stopped ports: - "80:80" - "443:443" environment: - MY_DOMAIN volumes: - ./Caddyfile:/etc/caddy/Caddyfile:ro - ./data:/data - ./config:/config networks: default: external: name: $DEFAULT_NETWORK 

WordPress-Compose:

version: '3.3' services: db: image: mysql:5.7 container_name: "mysql" hostname: "mysql" volumes: - db_data:/var/lib/mysql restart: unless-stopped environment: MYSQL_ROOT_PASSWORD: MYSQL_DATABASE: wordpress MYSQL_USER: MYSQL_PASSWORD: wordpress: depends_on: - db image: wordpress:latest container_name: "wordpress" hostname: "wordpress" restart: unless-stopped environment: WORDPRESS_DB_USER: WORDPRESS_DB_PASSWORD: WORDPRESS_DB_NAME: wordpress volumes: db_data: {} networks: default: external: name: $DEFAULT_NETWORK 

Nextcloud-compose:

version: '2' volumes: nextcloud: db: services: db: image: mariadb container_name: "mariadb" hostname: "mariadb" command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW restart: unless-stopped volumes: - db:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD= - MYSQL_PASSWORD= - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud nextcloud: image: nextcloud container_name: "nextcloud" hostname: "nextcloud" links: - db volumes: - nextcloud:/var/www/html restart: unless-stopped networks: default: external: name: $DEFAULT_NETWORK 

submitted by /u/IAmZacHarrisFromCary
[link] [comments]
Source: Reddit