1

I am trying to create 2 sites (with same code base just to test) to test SSO functionality (nothing to do with my question in terms of SSO) and I am using docker-compose.yml file for that. I have taken this copy of yml file online and it works fine in terms of setting up one site. I could docker-compose down and run second site and that will be fine too but I am not sure on how to setup 2 sites at the same time (www.site1.test & www.site2.test)

What changes do I need to make to this compose file or create a new file so that I have 2 sites at the same time.

version: "3.3"
services:
  wordpress:
    image: "wordpress:${WP_VERSION:-4.9.8}-php${PHP_VERSION:-7.2}-apache"
    environment:
      VIRTUAL_HOST: "${DOCKER_DEV_DOMAIN:-project.test}"
      WORDPRESS_DB_HOST: "mysql"
      WORDPRESS_DB_NAME: "wordpress"
      WORDPRESS_DB_PASSWORD: "password"
      WORDPRESS_DB_USER: "root"
    depends_on:
      - "mysql"
    networks:
      - "front"
      - "back"
    volumes:
      - "wp:/var/www/html:rw"
      - "./certs/ca-root/ca.crt:/tmp/certs/root.crt:ro"
      - "./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro"
      - "./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro"
      - "./src/site/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins"
      - "./src/site/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins"
      - "./src/site/images:/var/www/html/wp-content/images"
      - "./src/site/languages:/var/www/html/wp-content/languages"
      - "./src/site/plugins:/var/www/html/wp-content/plugins"
      - "./src/site/private:/var/www/html/wp-content/private"
      - "./src/site/themes:/var/www/html/wp-content/themes"
      - "./src/site/vip-config:/var/www/html/wp-content/vip-config"
  wp-cli:
    image: "wordpress:cli-php${PHP_VERSION:-7.2}"
    environment:
      - APACHE_RUN_USER="www-data"
      - APACHE_RUN_GROUP="www-data"
    depends_on:
      - "mysql"
    networks:
      - "back"
    volumes:
      - "wp:/var/www/html:rw"
      - "./bin/install-wp.sh:/usr/local/bin/install-wp:ro"
      - "./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro"
      - "./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro"
      - "./src/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins"
      - "./src/site/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins"
      - "./src/site/images:/var/www/html/wp-content/images"
      - "./src/site/languages:/var/www/html/wp-content/languages"
      - "./src/site/plugins:/var/www/html/wp-content/plugins"
      - "./src/site/private:/var/www/html/wp-content/private"
      - "./src/site/themes:/var/www/html/wp-content/themes"
      - "./src/site/vip-config:/var/www/html/wp-content/vip-config"
  photon:
    image: "chriszarate/photon:latest"
    networks:
      - "front"
  mysql:
    image: "mariadb:10.2"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_ROOT_PASSWORD: "password"
    networks:
      - "back"
    ports:
      - "3306:3306"
  proxy:
    image: "jwilder/nginx-proxy:alpine"
    environment:
      HSTS: "off"
      HTTPS_METHOD: "nohttps"
    ports:
      - "80:80"
      - "443:443"
    networks:
      front:
        aliases:
          - "${DOCKER_DEV_DOMAIN:-planetanalog.test}"
    volumes:
      - "//var/run/docker.sock:/tmp/docker.sock:ro"
      - "./certs/self-signed:/etc/nginx/certs:ro"
      - "./conf/nginx-proxy.conf:/etc/nginx/conf.d/proxy.conf:ro"
      - "./conf/nginx-proxy-wordpress.conf:/etc/nginx/vhost.d /${DOCKER_DEV_DOMAIN}_location:ro"

  networks:
    front: {}
    back: {}

  volumes:
    wp: {}

I am not an expert so I appreciate any answers.

TIA

Alp
  • 29,274
  • 27
  • 120
  • 198
Subrato M
  • 159
  • 1
  • 12

1 Answers1

0

I don't know how to do this with two different networks, but if you give your default network a custom name, you can use it and link containers in multiple compose files.

Example

Ditch the network blocks for each service and set a default network for each compose file.

docker-compose-backend.yml:

version: "3.3"
services:
  photon:
    image: "chriszarate/photon:latest"
  mysql:
    image: "mariadb:10.2"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      MYSQL_DATABASE: "wordpress"
      MYSQL_ROOT_PASSWORD: "password"
    ports:
      - "3306:3306"
  proxy:
    image: "jwilder/nginx-proxy:alpine"
    environment:
      HSTS: "off"
      HTTPS_METHOD: "nohttps"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "//var/run/docker.sock:/tmp/docker.sock:ro"
      - "./certs/self-signed:/etc/nginx/certs:ro"
      - "./conf/nginx-proxy.conf:/etc/nginx/conf.d/proxy.conf:ro"
      - "./conf/nginx-proxy-wordpress.conf:/etc/nginx/vhost.d /${DOCKER_DEV_DOMAIN}_location:ro"

  networks:
    default:
      external:
        name: back

  volumes:
    wp: {}

docker-compose-wp1.yml:

version: "3.3"
services:
  wordpress:
    image: "wordpress:${WP_VERSION:-4.9.8}-php${PHP_VERSION:-7.2}-apache"
    environment:
      VIRTUAL_HOST: "${DOCKER_DEV_DOMAIN:-project.test}"
      WORDPRESS_DB_HOST: "mysql"
      WORDPRESS_DB_NAME: "wordpress"
      WORDPRESS_DB_PASSWORD: "password"
      WORDPRESS_DB_USER: "root"
    depends_on:
      - "mysql"
    volumes:
      - "wp:/var/www/html:rw"
      - "./certs/ca-root/ca.crt:/tmp/certs/root.crt:ro"
      - "./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro"
      - "./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro"
      - "./src/site/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins"
      - "./src/site/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins"
      - "./src/site/images:/var/www/html/wp-content/images"
      - "./src/site/languages:/var/www/html/wp-content/languages"
      - "./src/site/plugins:/var/www/html/wp-content/plugins"
      - "./src/site/private:/var/www/html/wp-content/private"
      - "./src/site/themes:/var/www/html/wp-content/themes"
      - "./src/site/vip-config:/var/www/html/wp-content/vip-config"
  wp-cli:
    image: "wordpress:cli-php${PHP_VERSION:-7.2}"
    environment:
      - APACHE_RUN_USER="www-data"
      - APACHE_RUN_GROUP="www-data"
    depends_on:
      - "mysql"
    volumes:
      - "wp:/var/www/html:rw"
      - "./bin/install-wp.sh:/usr/local/bin/install-wp:ro"
      - "./conf/php-local.ini:/usr/local/etc/php/conf.d/local.ini:ro"
      - "./conf/wp-local-config.php:/usr/local/etc/php/autoprepend.php:ro"
      - "./src/vip-go-mu-plugins:/var/www/html/wp-content/mu-plugins"
      - "./src/site/client-mu-plugins:/var/www/html/wp-content/client-mu-plugins"
      - "./src/site/images:/var/www/html/wp-content/images"
      - "./src/site/languages:/var/www/html/wp-content/languages"
      - "./src/site/plugins:/var/www/html/wp-content/plugins"
      - "./src/site/private:/var/www/html/wp-content/private"
      - "./src/site/themes:/var/www/html/wp-content/themes"
      - "./src/site/vip-config:/var/www/html/wp-content/vip-config"

  networks:
    default:
      external:
        name: back

Then you can spin up more compose files like docker-compose-wp2.yml with similar content.

Community
  • 1
  • 1
Alp
  • 29,274
  • 27
  • 120
  • 198
  • I won't be sharing databases. Do I just move that section back to docker-compose-wp(n).yml? Also where do I put the docker-compose-backend.yml? In terms of directory structure – Subrato M Oct 01 '18 at 18:59
  • You can also put the database service to the wordpress compose file. Just move services to fit your application requirements. Since you use only images and no dockerfile builds it doesn't matter where the `.yml` files are. They could be all in the same dir or in different ones. Just be sure to `cd` to that dir when running `docker-compose`. – Alp Oct 12 '18 at 15:18