#TIL #docker 컨테이너에서 host로 접속은 어떻게 해야할까?

프로메테우스(prometheus)와 그라파나(grafana)를 테스트하고 싶다. 간편하게 docker를 사용해서 띄우고 host에서 실행하는 웹프레임워크 메트릭을 보고 싶다.

docker 컨테이너에서 host로 연결할 수 있을까? host ip는 어떻게 구해야 할까?

The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows.

- Networking features in Docker Desktop for Windows

host.docker.internal dns 이름을 사용하면 컨테이너에서 host로 접속할 수 있다.

scrape_configs:
- job_name: hello_metrics
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics
  scheme: http
  static_configs:
  - targets:
    - host.docker.internal:4000

docker 컨테이너로 띄운 프로메테우스에서 host.docker.internal dns 이름을 사용해 host의 메트릭을 긁어오게 설정했다.

Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com

A Random Post