도커에 톰켓을 설치한 상태이고, 호스트 아파치와 통신하기 위해 8009 포트를 활성해 했는데 통신이 안됩니다.
호스트 아파치 - 8009 잘됨 - 호스트 톰켓
호스트 아파치 - 8009 안됨 - 도커 톰켓
호스트 톰켓을 도커 톰켓으로 이관하려는 상황입니다.
8009 포트통신이 안되는데 어떻게 체크해볼 수 있고 어떻게 하면 될까요?
[호스트에서 도커 체크]
# telnet 172.17.0.3 8080
Trying 172.17.0.3...
Connected to 172.17.0.3.
Escape character is '^]'. => 잘됨
^CConnection closed by foreign host.
# telnet 172.17.0.3 8009
Trying 172.17.0.3...
telnet: connect to address 172.17.0.3: Connection refused => 안됨
# docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a
CONTAINER ID NAMES PORTS
047998d974de tomcat85-openjdk11-centos9 8009/tcp, 8080/tcp, 8443/tcp
af87c7594908 your_portainer_name 8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp
*. 컨테이너에는 분명히 8009, 8080, 8443 이 expose되어 있습니다.
[도커 내부에서 자기 자신 체크]
# vi /usr/local/tomcat/conf/server.xml
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector protocol="AJP/1.3"
address="0:0:0:0"
port="8009"
redirectPort="8443" secretRequired="false"/>
[root@047998d974de /]# telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'. => 잘됨
^CConnection closed by foreign host.
[root@047998d974de /]# telnet 127.0.0.1 8009
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'. => 잘됨
^CConnection closed by foreign host.
[root@047998d974de /]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
RX packets 16461 bytes 24744337 (23.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10017 bytes 754379 (736.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 36 bytes 6198 (6.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 36 bytes 6198 (6.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@047998d974de /]# getenforce
Disabled => selinux 꺼짐
[root@047998d974de /]# ps -ef | grep firewalld
root 127 56 0 15:54 pts/0 00:00:00 grep --color=auto firewalld => 방화벽 없음
어떻게 해야 8009번 포트가 호스트<->도커 간에 될까요 ?
netstat -nlp 해보시고 8009 열려있는지 체크하시고
방화벽도 체크 해보세요~
그리고 도커에서 포트포워딩 해주셧는지 체크
-------------------------
(도커 내부에서)
# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1/java
tcp 0 0 127.0.0.1:8009 0.0.0.0:* LISTEN 1/java
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 1/java
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
Active Bluetooth connections (only servers)
Proto Destination Source State PSM DCID SCID IMTU OMTU Security
Proto Destination Source State Channel
-------------------------------------
위에 썼듯이 방화벽은 실행되고 있지 않습니다.
이경우 안된다면 -p 아무다른포트:8009 를 주시고,
해당 포트로는 통신이 되는지 확인해 보는 것이 좋을 것 같습니다.
# docker container ls --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}" -a
CONTAINER ID NAMES PORTS
df33e6124676 tomcat85-openjdk11-centos9 0.0.0.0:18009->8009/tcp, :::18009->8009/tcp, 0.0.0.0:18080->8080/tcp, :::18080->8080/tcp, 0.0.0.0:32777->8443/tcp, :::32777->8443/tcp
# telnet 172.17.0.3 18080
Trying 172.17.0.3...
telnet: connect to address 172.17.0.3: Connection refused
말씀하신대로 18009->8009 로 줘봤는데도 안되네요...
0.0.0.0:8009. 를 listen 하지 않아서 그런 것 같습니다.
docker 도 포트포워딩이 연결되려면 0.0.0.0 포트로 받아야 외부 listen 이 되는 것 같고요. 제가 실제 서비스 하는 도커 내부의 netstat 찍어보니까
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN
이렇게 되네요
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 1/java
tcp 0 0 127.0.0.1:8009 0.0.0.0:* LISTEN 1/java
이것 말씀이실까요 ? 8080과 8009가 차이가 있긴하네요.
그런데 127.0.0.1 은 local address 이고 Foreign address는 0.0.0.0* 으로 듣는다고 되어 있는데 이설정도 외부와 8009 통신이 되야 하는거 아닐까요 ? (질문)
# netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:18080 0.0.0.0:* LISTEN 94518/docker-proxy
tcp 0 0 0.0.0.0:18009 0.0.0.0:* LISTEN 94540/docker-proxy
도커내부 8009 서비스 하는곳 설정 파일에 bind address 쪽을 0.0.0.0 을 하시면 해결 될 것 같습니다.