Accessing container on port 3000 thru traefik

試著忘記壹切 提交于 2020-05-15 21:21:28

问题


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

The node-js app runs on port 3000

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

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

Trying to connect:

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

Bad Gateway

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

curl: (52) Empty reply from server

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


回答1:


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.

removed - "traefik.backend.port=3000" from the docker-compose.yml

added 127.0.0.1 microservice.docker.localhost to /etc/hosts

which rendered me able to:

curl http://microservice.docker.localhost/ and get the response I was expecting

I'm a microservice!



来源:https://stackoverflow.com/questions/45920765/accessing-container-on-port-3000-thru-traefik

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!