[DEV] 기록

[Windows + Docker] Socket fail to connect to host:address=(host=localhost)(port=

꾸준함. 2023. 11. 11. 04:18

개요

스프링부트 서버가 도커로 띄운 MariaDB를 접근하는데 아래와 같은 에러와 함께 지속적으로 실패했습니다.
 

Socket fail to connect to host:address=(host=localhost)(port=3306)(type=primary). 
Connection refused: no further information

 
위와 같은 에러가 발생해서 도커 컨테이너를 재기동 시도했는데 stop 이후 start가 안되고 아래와 같은 에러가 발생했습니다.
 

Ports are not available: listen tcp 0.0.0.0/3306: 
bind: An attempt was made to access a socket in a way forbidden by its access permissions

 

원인

윈도우의 Windows NAT Driver인 winnat에 의해 발생하는 버그로 winnat을 멈춘 상태에서 docker를 띄우고 다시 실행해 주면 된다고 합니다.
 
출처: https://github.com/docker/for-win/issues/3171#issuecomment-739740248

Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges · Issue #3171 · docker/for-wi

I have tried with the latest version of my channel (Stable or Edge) I have uploaded Diagnostics Diagnostics ID: BB0297BB-C287-4F0B-A007-72B5F2D7BD72/20190102235413 Expected behavior Be able to bind...

github.com

 

해결 방법

관리자 권한으로 cmd를 실행하고 아래와 같이 명령어를 작성하면 됩니다.
 

net stop winnat
docker start [컨테이너명]
net start winnat

 

 

출처

https://stackoverflow.com/questions/65272764/ports-are-not-available-listen-tcp-0-0-0-0-50070-bind-an-attempt-was-made-to

Ports are not available: listen tcp 0.0.0.0/50070: bind: An attempt was made to access a socket in a way forbidden by its access

I am trying to start a docker container with the below command. docker run -it -p 50070:50070 -p 8088:8088 -p 8080:8080 suhothayan/hadoop-spark-pig-hive:2.9.2 bash It ended up with the following e...

stackoverflow.com

 

반응형