도커에 톰켓을 설치한 상태이고, 호스트 아파치와 통신하기 위해 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
ÀÌ°Í ¸»¾¸À̽DZî¿ä ? 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 À» ÇϽøé ÇØ°á µÉ °Í °°½À´Ï´Ù.