도커 컨테이너에서 호스트의 서비스 포트에 접속하는 방법

사진: UnsplashVenti Views

상황

노트북(윈도 10)에 Docker Desktop을 설치하여 여러 Container를 돌리고 있다. 

노트북에 설치한 IntelliJ IDEA에서 자바로 테스트용 소켓 서버를 작성했다. 

Docker Container에서 테스트용 소켓 서버로 데이터를 보내야 한다. 


방법

Docker Container에서 호스트를 목적지로 하는 방법은 간단하다. IP 대신 아래 2개의 DNS 이름을 사용하는 것이다. 

  • host.docker.internal
  • gateway.docker.internal

어떻게 가능할까? Docker Desktop이 노트북의 hosts 파일에 아래와 같이 설정해 놓았기 때문이다. 

1
2
3
4
5
6
# Added by Docker Desktop
192.168.19.48 host.docker.internal
192.168.19.48 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
cs


참고

https://docs.docker.com/desktop/networking/

댓글 달기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

위로 스크롤