为什么 Podman 无法识别主机名,如何解决?

这是我的podman-compose 配置文件

 php8: 
    hostname: php8
    container_name: php8
    image: php8:latest
    volumes:
      - ./www:/var/www
      - ./config/php8:/usr/local/etc/php/conf.d
    restart: always
  caddy:
    container_name: caddy
    hostname: caddy
    image: caddy:latest
    restart: always
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./config/caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./www:/srv
      - ./config/caddy/data:/data
      - ./config/caddy/config:/config

错误提示:

{"level":"error",
"ts":1737361804.6081245,
"logger":"http.log.error",
"msg":"dialing backend: dial tcp: lookup php8 on 114.114.114.114:53: no such host",
"request":{"remote_ip":"192.168.8.166","remote_port":"55861","client_ip":"192.168.8.166","proto":"HTTP/1.1","method":"GET","host":"www.hszh.com","

这里提示:这个主机名php8 找不到。

我的caddyfile 的配置是

http://www.hszh.com {
……
    php_fastcgi * php8:9000 {
       …………
  }
……
}

这里的php8 是容器名称。

我不知道是怎么会事!我的 debian 就是正常的,但是我现在是用的是openEuler系统,debian同样的配置都是没有问题的,现在就出现了这样的问题。

请问这个情况如何处理 openeuler 需要配置?podman 需要配置?

无效的方法(尝试过添加自定义网络)

  php8: 
    hostname: php8
    container_name: php8
    image: php8:latest
    volumes:
      - ./www:/var/www
      - ./config/php8:/usr/local/etc/php/conf.d
    restart: always
    networks:
      - my_network
  caddy:
    container_name: caddy
    hostname: caddy
    image: caddy:latest
    restart: always
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./config/caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./www:/srv
      - ./config/caddy/data:/data
      - ./config/caddy/config:/config
    networks:
      - my_network
networks:
  my_network:
    name: my_custom_network
    driver: bridge
阅读 369
1 个回答
version: '3'
services:
  php8: 
    hostname: php8
    container_name: php8
    image: php8:latest
    volumes:
      - ./www:/var/www
      - ./config/php8:/usr/local/etc/php/conf.d
    restart: always
    networks:
      default:
        aliases:
          - php8
  caddy:
    container_name: caddy
    hostname: caddy
    image: caddy:latest
    restart: always
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./config/caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./www:/srv
      - ./config/caddy/data:/data
      - ./config/caddy/config:/config
    networks:
      default:
        aliases:
          - caddy

networks:
  default:
    name: podman_default
    driver: bridge
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏