通过 traefik 访问端口 3000 上的容器 [英] Accessing container on port 3000 thru traefik

查看:34
本文介绍了通过 traefik 访问端口 3000 上的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆