本地计算机上的多个站点以及Windoows上的docker

时间:2018-09-27 16:37:09

标签: docker docker-compose jwilder-nginx-proxy

我试图创建2个站点(使用相同的代码库进行测试)来测试SSO功能(与我在SSO方面的问题无关),并且我为此使用了docker-compose.yml文件。我已经将此yml文件的副本在线获取,并且在设置一个站点方面效果很好。我可以泊坞窗组成并运行第二个站点,这也可以,但我不确定如何同时设置两个站点(www.site1.test和www.site2.test)

我需要对此撰写文件进行什么更改或创建一个新文件,以便同时拥有2个站点。

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: {}

我不是专家,所以我感谢任何答复。

TIA

1 个答案:

答案 0 :(得分:0)

我不知道如何在两个不同的网络中执行此操作,但是如果您为默认网络指定了自定义名称,则可以使用它并在多个撰写文件中链接容器。

示例

抛弃每个服务的网络块,并为每个撰写文件设置默认网络。

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

然后,您可以启动具有类似内容的更多撰写文件,例如docker-compose-wp2.yml