利用 podman-compose 在 Windows 上使用 Podman 设置 Traefik 代理

问题描述 投票:0回答:1

我在 Windows 上使用 Podman (https://github.com/containers/podman/blob/main/docs/tutorials/podman-for-windows.md) 以及 podman-compose (https://github) .com/containers/podman-compose?tab=readme-ov-file#pip)

>podman --version
 podman version 5.0.2

>podman machine inspect
[
     {
          "ConfigDir": {
               "Path": "C:\\Users\\...\\.config\\containers\\podman\\machine\\wsl"
          },
          "ConnectionInfo": {
               "PodmanSocket": null,
               "PodmanPipe": {
                    "Path": "\\\\.\\pipe\\podman-machine-default"
               }
          },
          "Created": "2024-10-28T17:01:13.1163465+01:00",
          "LastUp": "0001-01-01T00:00:00Z",
          "Name": "podman-machine-default",
          "Resources": {
               "CPUs": 10,
               "DiskSize": 100,
               "Memory": 2048,
               "USBs": []
          },
          "SSHConfig": {
               "IdentityPath": "C:\\Users\\...\\.local\\share\\containers\\podman\\machine\\machine",
               "Port": 56403,
               "RemoteUsername": "user"
          },
          "State": "running",
          "UserModeNetworking": false,
          "Rootful": true
     }
]


>podman-compose --version
podman-compose version: 1.0.6

我有一个

compose.yaml
文件,我尝试在其中为我的服务设置 Traefik 代理:

services:

reverse-proxy:
  container_name: traefik-reverse-proxy
  image: traefik:v3.1
  command:
    - "--api.insecure=true"
    - "--api.dashboard=true"
    - "--providers.docker=true"
    - "--providers.docker.exposedbydefault=false"
    - "--entrypoints.web.address=:80"
  ports:
    - "80:80"
    - "8080:8080"  # Traefik dashboard
  volumes:
    - "/var/run/docker.sock:/var/run/docker.sock"  
  restart: unless-stopped
  labels:
    - "traefik.enable=true"
    - "traefik.http.routers.api.rule=Host(`traefik.localhost`)"

backend:
  depends_on: 
    - reverse-proxy 
  container_name: my-api-container
  image: gitlab-registry....:latest
  pull_policy: always
  restart: unless-stopped
  labels:
    - "traefik.enable=true"
    - "traefik.http.routers.backend.rule=Host(`backend.localhost`)"
    - "traefik.http.routers.backend.entrypoints=web"

运行后

podman-compose up -d
我可以访问
http://traefik.localhost:8080/dashboard/#/
下的Traefik仪表板,但不能访问我的后端容器。
执行
podman logs -t traefik-reverse-proxy
后会显示以下错误:

ERR Failed to retrieve information of the docker client and server host error="Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" providerName=docker
ERR Provider error, retrying in 318.953454ms error="Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?" providerName=docker  

我需要如何调整 compose.yaml/Traefik 配置才能在 Windows 上成功将 Traefik Proxy 与 Podman-Compose 结合使用?

当我尝试使用 npipe 映射 compose.yaml 中的卷时:

volumes:
  - "//./pipe/podman-machine-default:/var/run/docker.sock" 

我收到错误:

OSError: [WinError 231] All pipe instances are busy: '\\\\.\\pipe\\podman-machine-default'
docker docker-compose traefik podman podman-compose
1个回答
0
投票

Docker 套接字与 podman 的映射应该是这样的:

/run/user/<user>/podman/podman.sock:/var/run/docker.sock:z

Podman 套接字必须以以下方式启动:

$ systemctl --user start podman.socket

参考:https://blog.cthudson.com/2023-11-02-running-traefik-with-podman/

© www.soinside.com 2019 - 2024. All rights reserved.