首页 文章

设置 weweave commerce 和 traefik

提问于
浏览
0

我正在尝试使用 docker 设置 weweave commerce。但是在第 4 步呢

使用像 Traefik(或 nginx 或 haproxy)这样的云本机边缘路由器:将所有传入的请求路由到/api/到后端。将所有其他传入请求路由到前端。

我怎样才能做到这一点?我在 weweave 文档中找不到它,我不理解 traefik 文档。

**更新:**我现在从源代码构建它并且它可以工作。我将尝试给出的答案,如果有效,我会做出反应,如果你有同样的问题可以使用它。

1 回答

  • 0

    我设法使用以下 compose 文件获取此 up-and-running。使用以下内容在新文件夹中创建config.json文件:

    {
        "database": {
            "driver": {
                "type": "mysql",
                "host": "mysql",
                "port": 3306,
                "username": "root",
                "password": "my-secret-pw",
                "database": "commerce"
            },
            "logging": ["error", "warn"]
        },
        "basePath": "/",
        "session": {
            "secret": "fkj49l7WwjUtqcfLZKlLA269J28kC4uL",
            "issuer": "https://change.me",
            "lifetime": "12h"
        },
        "importTldListOnStart": true
    }
    

    使用以下内容在同一文件夹中创建docker-compose.yml

    version: '3'
    
    services:
      # The reverse proxy service (Traefik)
      reverse-proxy:
        image: traefik  # The official Traefik docker image
        command: --web --docker --docker.domain=docker.localhost --logLevel=DEBUG
        ports:
          - "80:80"      # The HTTP port
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock  # So that Traefik can listen to the Docker events
    
      mysql:
        image: mysql:5.6
        environment:
          MYSQL_ROOT_PASSWORD: my-secret-pw
          MYSQL_DATABASE: commerce
    
      commerce:
        image: weweave/commerce
        ports:
          - "3000:3000"
        depends_on:
          - "mysql"
        volumes:
          - ./config.json:/usr/src/app/config.json
        labels:
          - "traefik.frontend.rule=Host:commerce.docker.localhost;PathPrefix:/api/"
          - "traefik.port=3000"
    
      commerce-www:
        image: weweave/commerce-www
        ports:
          - "8080:8080"
        depends_on:
          - "commerce"
        labels:
          - "traefik.frontend.rule=Host:commerce.docker.localhost"
    

    docker-compose up -d打造整个东西

    然后打开浏览器并导航到:http://commerce.docker.localhost

相关问题