Docker Community Forums

Share and learn in the Docker community.

Webhost - NGINX, WordPress, MariaDB, Assistance/Advice pls

docker

(Cloudjumper2000) #1

Following this guide for reference and now I want to add a 2nd then a 3rd WordPress site.

So the site1 docker-compose.yml file:

services:
   db:
     image: mariadb
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: password
       MYSQL_DATABASE: site1db
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
     container_name: maria_db

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     expose:
       - 80
     restart: always
     environment:
       VIRTUAL_HOST: site1.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     container_name: site1.com
volumes:
    db_data:

networks:
  default:
    external:
      name: nginx-proxy

So now I want to add a 2nd WordPress site using this same maria_db container just creating a new DB, possibly new un/pw. How can I do this?

I am guessing I can create the site by the following:
site 2 docker-compose.yml

version: "3"

services:
   wordpress:
     image: wordpress:latest
     expose:
       - 80
     restart: always
     environment:
       VIRTUAL_HOST: site2.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     container_name: site2.com

networks:
  default:
    external:
      name: nginx-proxy

Only now it seems the NGINX redirect is pointing to site1.com

So 2 questions.

How do I create a 2nd site connection to a single DB Container
(Is this advised? or should each WP Container have its own DB Container?)
What am I doing wrong with the site 2 docker-compose.yml.


(Sam) #2

add another wordpress service, wordpress2 that has all the rest with a different db name and password…
for the second db see https://github.com/laradock/laradock/issues/616

services:
   db:
     image: mariadb
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: password
       MYSQL_DATABASE: site1db
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
     container_name: maria_db

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     expose:
       - 80
     restart: always
     environment:
       VIRTUAL_HOST: site1.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     container_name: site1.com

   wordpress2:
     depends_on:
       - db
     image: wordpress:latest
     expose:
       - 80
     restart: always
     environment:
       VIRTUAL_HOST: site2.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     container_name: site2.com
volumes:
    db_data:

networks:
  default:
    external:
      name: nginx-proxy

(Cloudjumper2000) #3

First off thanks for taking the time to respond.

My scenario is a situation where I have site1.com and mariadb already running and I want to add an additional site to the server not starting from scratch. I believe in the scenario above you replied with it would simply add 2 sites from the start which helps but i know down the line id like to add/remove sites adhoc without taking down existing sites.

Thoughts?


(Sam) #4

i do not see any doc on how to adjust a deployed solution using docker-compose.

i see doc on ‘if the service is found it is taken down and a new one is started’… when you use a total new compose file.

see https://docs.docker.com/compose/production/#deploying-changes

Deploying changes
When you make changes to your app code, you’ll need to rebuild your image and recreate your app’s containers. To redeploy a service called web, you would use:

$ docker-compose build web
$ docker-compose up --no-deps -d web
This will first rebuild the image for web and then stop, destroy, and recreate just the web service. The --no-deps flag prevents Compose from also recreating any services which web depends on.

(Cloudjumper2000) #5

Hrmmm…

So while I get that scenario as well I still dont think that exactly takes into consideration an additional container rather it appears its a change to an existing one.

Issue I see happening here is by redeploying or “Deploying Changes” site1 has a high probability of data loss and being reset back to a default WP build.

Think of this as a webhost company. In January I have 2 websites, Feb I need to add 1 more. I cant take down the all the websites to add additional ones each time I get new clients. They would face downtime and potential data loss each time I take on a new site.

Anything im missing here? Am I going about this the wrong way?


(Sam) #6

i understand, and agree that there seems to be some missing info, or function…

I would not want to ‘take down’ an existing…

this sort of sounds like you want to do swarm, with ‘replicas’,
where you can change the count…


(Cloudjumper2000) #7

So I dont mind doing a swarm only this is a single host. Does that make any difference?


(Sam) #8

Swarm is containers… (and maybe multiple hosts too)…