Closed Jongmo-kim closed 2 years ago
해당 링크를 참고하여 도커 컨테이너에서 로컬 DB에 접속하는 방법을 찾았습니다.
도커 실행시 다음과 같은 명령어를 추가합니다.
--add-host=host.docker.internal:172.17.0.1
그러면 도커 컨테이너 내부에서 ping host.docker.internal을 실행시 172.17.0.1로 변환되어 ping 명령어가 실행됩니다.
이름 | 포트 |
---|---|
SSH | 19620 |
postgresql | 19621 |
docker | 19622 |
WAS | 19623 |
sonarqube | 19624 |
와 같이 포트를 설정했습니다.
모든 도커 컨테이너의 network를 bridge로 설정했습니다.
서버 재부팅시 실행해야하는 명령어들입니다.
sudo service ssh restart
sudo dockerd
sudo /etc/init.d/postgresql restart
sudo chmod 666 /var/run/docker.sock
docker run -d --restart always --name jenkins --add-host=host.docker.internal:172.17.0.1 -p 19622:8080 -v $PWD/jenkins_home:/var/jenkins_home -v /usr/bin/docker:/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins
docker run -d --name sonarqube -p 19624:9000 --add-host=host.docker.internal:172.17.0.1 -e sonar.jdbc.url=jdbc:postgresql://host.docker.internal:19621/postgres -e sonar.jdbc.username=sonarqube -e sonar.jdbc.password=sonar-pass --ulimit nofile=65536:65536 sonarqube
docker run -d --name server -p 9090:19623 --add-host=host.docker.internal:172.17.0.1 docker-example:0.0.1
docker run -d --name sonarqube -p 19624:9000 --add-host=host.docker.internal:172.17.0.1 -e sonar.jdbc.url=jdbc:postgresql://host.docker.internal:19621/postgres -e sonar.jdbc.username=sonarqube -e sonar.jdbc.password=sonar-pass --ulimit nofile=65536:65536 sonarqube
에서 --ulimit nofile=65536:65536는 다음 링크를 참고하여 적용했습니다.https://stackoverflow.com/a/58024178
포트가 정리되었으므로 이슈를 닫습니다.
현재 postgres : 19621, jenkins : 8080, sonarqube : 9000, ssh : 19620 과 같이 포트가 할당되어 있고 각 서버들이 부가적으로 사용하는 포트또한 사용되어지고 있습니다.
이는 도커의 네트워크를 bridge가 아닌 host로 설정해서 발생하는 문제입니다.
도커의 네트워크 구조를 파악하여 원하는 포트만 밖으로 할당되게 합니다 도커 컨테이너 내부에서 로컬 네트워크가 필요한경우 포트만 할당할수 있도록 네트워크를 구성합니다.