You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

配置Mailcow与Traefik遇问题,寻求技术协助

Mailcow 搭配 Traefik 配置排查与修正

我在配置Mailcow的docker-compose.override.yml以适配Traefik时遇到问题,无法定位错误点,以下是我的配置文件,寻求技术协助:

version: '2.1'

services:
    nginx-mailcow:
      networks:
        # Add Traefik's network
        - proxy
      labels:
        - traefik.enable=true
        # Creates a router called "moo" for the container, and sets up a rule to link the container to certain rule,
        #   in this case, a Host rule with our MAILCOW_HOSTNAME var.
        - traefik.http.routers.moo.rule=Host(`${MAILCOW_HOSTNAME}`)
        # Enables tls over the router we created before.
        - traefik.http.routers.moo.tls=true
        # Specifies which kind of cert resolver we'll use, in this case le (Lets Encrypt).
        - traefik.http.routers.moo.tls.certresolver=le
        # Creates a service called "moo" for the container, and specifies which internal port of the container
        #   should traefik route the incoming data to.
        - traefik.http.services.moo.loadbalancer.server.port=${HTTP_PORT}
        # Specifies which entrypoint (external port) should traefik listen to, for this container.
        #   websecure being port 443, check the traefik.toml file liked above.
        - traefik.http.routers.moo.entrypoints=websecure
        # Make sure traefik uses the web network, not the mailcowdockerized_mailcow-network
        - traefik.docker.network=proxy

    certdumper:
        image: humenius/traefik-certs-dumper
    command: --restart-containers ${COMPOSE_PROJECT_NAME}-postfix-mailcow-1,${COMPOSE_PROJECT_NAME}-nginx-mailcow-1,${COMPOSE_PROJECT_NAME}-dovecot-mailcow-1
        network_mode: none
        volumes:
          # Mount the volume which contains Traefik's `acme.json' file
          #   Configure the external name in the volume definition
          - /home/archmatt/traefik/data/acme.json:/traefik:ro
          # Mount mailcow's SSL folder
          - ./data/assets/ssl/:/output:rw
          # Mount docker socket to restart containers
          - /var/run/docker.sock:/var/run/docker.sock:ro
        restart: always
        environment:
          # only change this, if you're using another domain for mailcow's web frontend compared to the standard config
          - DOMAIN=${MAILCOW_HOSTNAME}

networks:
  web:
    external: true
    # Name of the external network
    name: proxy

volumes:
  acme:
    external: true
    # Name of the external docker volume which contains Traefik's `acme.json' file
    name: proxy

配置中的关键错误与修正方案

1. certdumper 服务缩进错误

command 行未对齐到 certdumper 服务层级,会导致Docker Compose解析失败。修正后:

certdumper:
    image: humenius/traefik-certs-dumper
    command: --restart-containers ${COMPOSE_PROJECT_NAME}-postfix-mailcow-1,${COMPOSE_PROJECT_NAME}-nginx-mailcow-1,${COMPOSE_PROJECT_NAME}-dovecot-mailcow-1
    network_mode: none
    # 其余配置保持不变

2. 网络定义不匹配

  • nginx-mailcow 中使用了proxy网络,但你在networks块定义的是web并指向外部proxy网络,命名混淆。建议统一命名:
    networks:
      proxy:
        external: true
        name: proxy
    
  • nginx-mailcow 需要保留Mailcow默认内部网络(通常为mailcowdockerized_mailcow-network),否则无法与其他Mailcow组件通信。修正后:
    nginx-mailcow:
      networks:
        - mailcowdockerized_mailcow-network
        - proxy
    

3. Volumes 配置冗余错误

你直接挂载了本地文件/home/archmatt/traefik/data/acme.json,定义的acme卷完全冗余,可直接删除该卷配置。若要使用卷挂载,可替换为:

volumes:
  - traefik-acme:/traefik:ro  # 假设Traefik的acme.json存储在名为traefik-acme的卷中

4. Traefik 端口与变量优化

  • ${HTTP_PORT} 变量可直接写死为Mailcow nginx容器默认内部端口8080,避免变量解析问题。
  • 确认Traefik配置中已正确定义websecure入口点(对应443端口),且le证书解析器已完成Let's Encrypt配置。

修正后的完整配置示例

version: '2.1'

services:
    nginx-mailcow:
      networks:
        - mailcowdockerized_mailcow-network
        - proxy
      labels:
        - traefik.enable=true
        - traefik.http.routers.moo.rule=Host(`${MAILCOW_HOSTNAME}`)
        - traefik.http.routers.moo.tls=true
        - traefik.http.routers.moo.tls.certresolver=le
        - traefik.http.services.moo.loadbalancer.server.port=8080
        - traefik.http.routers.moo.entrypoints=websecure
        - traefik.docker.network=proxy

    certdumper:
        image: humenius/traefik-certs-dumper
        command: --restart-containers ${COMPOSE_PROJECT_NAME}-postfix-mailcow-1,${COMPOSE_PROJECT_NAME}-nginx-mailcow-1,${COMPOSE_PROJECT_NAME}-dovecot-mailcow-1
        network_mode: none
        volumes:
          - /home/archmatt/traefik/data/acme.json:/traefik:ro
          - ./data/assets/ssl/:/output:rw
          - /var/run/docker.sock:/var/run/docker.sock:ro
        restart: always
        environment:
          - DOMAIN=${MAILCOW_HOSTNAME}

networks:
  proxy:
    external: true
    name: proxy

排查步骤建议

  1. 运行 docker-compose -f docker-compose.yml -f docker-compose.override.yml config 检查配置语法,无输出报错则语法正常。
  2. 查看Traefik容器日志,确认是否存在路由或证书相关错误。
  3. 查看nginx-mailcow等Mailcow组件日志,确认容器是否正常启动并能接收Traefik转发请求。

内容的提问来源于stack exchange,提问作者ArchMatt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 05:55:24