WordPress部署具有许多节点和traefik的副本

时间:2019-02-11 16:47:11

标签: wordpress docker docker-swarm traefik docker-swarm-mode

当我连接到wordpress时,该网站要求我在几秒钟后再次登录。 群集具有多个节点,并且仅当我尝试部署多个副本时才会出现此问题。 在互联网上,每个人都建议使用traefik,但是即使尝试查找和使用一些文档以及一些示例,问题仍然存在。 代码如下,如果有人有任何想法或类似的建议,我将非常有帮助。一般而言,我从来没有使用过traefik或proxy,因此我对此主题没有任何准备。

After 2 seconds setTimeout will execute showing Linda's updated info:<br />
<div id="container"></div>

1 个答案:

答案 0 :(得分:0)

我猜你在使用群体。

https://docs.traefik.io/v1.7/configuration/backends/docker/#using-docker-with-swarm-mode

标签必须在deploy部分中定义。

version: '3.1'
services:

  traefik:
    image: traefik
    command: --docker --docker.swarmmode \
               --docker.watch \
               --web \
               --loglevel=DEBUG
    ports:
      - 8081:80
      - 9095:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.role == manager]
    networks:
      - rete

  wordpress:
    depends_on:
      - database
    image: 'wordpress:php7.2-apache'
    restart: always
    deploy:
      replicas: 5
      labels: 
        - "traefik.docker.network=sito_rete"
        - "traefik.port=8090"
        - "traefik.frontend.rule=Host:192.168.1.5"
        - "traefik.backend.loadbalancer.sticky=true"
        - "traefik.backend.loadbalancer.swarm=true"
    ports:
      - '8090:80'
    environment:
      WORDPRESS_DB_HOST: database
      WORDPRESS_DB_USER: user
      WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password
      WORDPRESS_DB_NAME: db
    secrets:
      - db_password
    volumes:
      - 'wp_data:/var/www/html'
    networks:
      - rete

  database:
    image: 'mysql:5.7'
    environment:
      MYSQL_DATABASE: db
      MYSQL_USER: user
      MYSQL_PASSWORD_FILE: /run/secrets/db_password
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
    secrets:
      - db_password
      - db_root_password
    volumes:
      - 'wp_db_data:/var/lib/mysql'
    networks:
      - rete
secrets:
  db_password:
    external: true
  db_root_password:
    external: true
volumes:
  wp_db_data:
    external: true
  wp_data:
    external: true

networks:
  rete:
    driver: overlay