Certimate 无法部署证书至宿主机的问题及解决

背景 Certimate 是一个开源的 SSL 证书管理工具,可以通过工作流实现自动申请、部署 SSL 证书,并在证书即将过期时自动续期。 而问题就出现

背景

Certimate 是一个开源的 SSL 证书管理工具,可以通过工作流实现自动申请、部署 SSL 证书,并在证书即将过期时自动续期。
而问题就出现在将证书部署在 1Panel 网站阶段。工作流运行后有如下输出:
ScreenShot_2025-07-10_11-12-52.png

分析

关键问题在于:Get "https://127.0.0.1:4399/api/v2/websites/ssl/1": dial tcp 127.0.0.1:4399: connect: connection refused
该错误表明 Certimate 容器无法访问宿主机上运行的 1Panel API 服务。经过排查,发现这是由于 Docker 容器的网络隔离机制导致的问题。
具体表现在:Certimate 通过 Docker 部署,默认使用 Bridge 网络模式。在 Bridge 模式下,容器内访问 127.0.0.1 会指向容器自身,而非宿主机,导致无法连接到宿主机的 1Panel 服务(监听在 127.0.0.1:4399)。
网络环境概述 - Docker容器与宿主机通信问题.png

解决

通过将 Certimate 容器的网络模式设置为 host,并移除冗余的 networks 配置后成功修复问题。以下是修复后的 Compose 文件:

services:
    certimate:
        container_name: ${CONTAINER_NAME}
        deploy:
            resources:
                limits:
                    cpus: ${CPUS}
                    memory: ${MEMORY_LIMIT}
        environment:
            - http_proxy=${PANEL_HTTP_PROXY}
            - https_proxy=${PANEL_HTTPS_PROXY}
            - NO_PROXY=${PANEL_NO_PROXY}
        image: certimate/certimate:v0.3.21
        labels:
            createdBy: Apps
        network_mode: host    # 新增这一行
        ports:
            - ${HOST_IP}:${PANEL_APP_PORT_HTTP}:8090
        restart: unless-stopped
        volumes:
            - /etc/localtime:/etc/localtime:ro
            - /etc/timezone:/etc/timezone:ro
            - ./data:/app/pb_data

完成修改后重建应用,经过测试问题就这样解决啦🥰
ScreenShot_2025-07-10_11-14-13.png