💡Aha!

docker에서 호스트 네트워크 접근하기

문제점

docker로 웹 서버를 구성했는데, 웹 서버에서 호스트에 구성되어 있는 서비스를 리버스 프록시로 넘겨줘야 할 일이 생겼다. 물론 호스트에 구성되어 있는 서비스를 Docker로 넣으면 좋겠지만, 해당 서비스는 Docker로 구성되어 있지 않다는 점이 문제.

해결

Use host networking
If you use the host network mode for a container, that container's network stack is not isolated from the Docker host (the container shares the host's networking namespace), and the container does not get its own IP-address allocated.
Use host networking
https://docs.docker.com/network/host/
Use host networking

네트워크 세팅을 host 모드로 변경하면 호스트 네트워크에 간단하게 접근할 수 있다.

Docker 명령어인 경우:

1--network host

Docker Compose 인 경우:

1network_mode: "host"

주의할 점

Host 네트워크 드라이버는 호스트와 직렬되기 때문에, 도커의 bridge 네트워크가 제공하는 여러 기능들을 사용할 수 없게 된다.

불가피 한 경우가 아니라면 가능하면 서비스는 도커로 모두 넣는 것이 좋을 듯...

또한 Host 네트워크는 Docker Swarm에서는 사용할 수 없다고 한다.

2024 Dohyun Jung.
Made with ☕️.