通过 traefik 访问端口 3000 上的容器

编程入门 行业动态 更新时间:2024-10-27 14:26:02
本文介绍了通过 traefik 访问端口 3000 上的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

好的,我有一个 node-js 应用,我想通过 traefik 访问.

Okay, so I've got a node-js app I'd like to access thru traefik.

node-js 应用程序运行在端口 3000

The node-js app runs on port 3000

按照入门页面中的 test-it 说明操作后,我已经运行了 traefik.

I've got traefik running after following the test-it instructions from the getting started page.

docker-compose.yml

docker-compose.yml

version: '2'
services:

  app:
    build:
      context: .
      dockerfile: docker/app/Dockerfile
    environment:
      - NODE_ENV=development
      - NODE_PORT=3000
    volumes:
      - ./app:/app
    expose:
      - "3000"
    networks:
      - web
    labels:
      - "traefik.backend=microservice"
      - "traefik.backend.port=3000"
      - "traefik.port=3000"
      - "traefik.frontend.rule=Host:microservice.docker.localhost"
networks:
  web:
    external:
      name: traefik_webgateway

尝试连接:

curl -H Host:microservice.docker.localhost http://localhost/

坏网关

curl -H Host:microservice.docker.localhost http://localhost:3000/

curl: (52) 来自服务器的空回复

curl: (52) Empty reply from server

但是 curl -H Host:whoami.docker.localhost http://localhost/ 像预期的那样工作.

But curl -H Host:whoami.docker.localhost http://localhost/ works like intended.

推荐答案

问题是我的微服务必须监听 localhost:3000 而我把它改成了 0.0.0.0:3000,它就像一个魅力.

The problem was that my microservice was bound to listen to localhost:3000 instead I changed it to 0.0.0.0:3000 and it worked like a charm.

docker-compose.yml

127.0.0.1 microservice.docker.localhost 添加到 /etc/hosts

这让我能够:

curl http://microservice.docker.localhost/ 并得到我期待的响应

我是一个微服务!

这篇关于通过 traefik 访问端口 3000 上的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 02:04:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1198670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   容器   traefik

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!