Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

docker - RULE_APPEND failed (No such file or directory): rule in chain DOCKER

docker run 시에 포트를 지정했더니 오류가 발생합니다.

$ docker run -p 15000:15000 hello-world
docker: Error response from daemon: driver failed programming external connectivity on endpoint eloquent_goldwasser (132d751ee683967072afa5ea77a3cb217b817fcc5f1fb2aa45306316cfd749a7): Unable to enable DNAT rule:  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 15000 -j DNAT --to-destination 172.17.0.2:15000 ! -i docker0: Warning: Extension tcp revision 0 not supported, missing kernel module?
Warning: Extension DNAT revision 0 not supported, missing kernel module?
iptables v1.8.10 (nf_tables):  RULE_APPEND failed (No such file or directory): rule in chain DOCKER
 (exit status 4)).

메시지에 나온 명령어를 그대로 실행해도 오류가 재현되는데요,

$ iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 15000 -j DNAT --to-destination 172.17.0.2:15000 ! -i docker0
iptables v1.8.10 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)

$ sudo iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 15000 -j DNAT --to-destination 172.17.0.2:15000 ! -i docker0
Warning: Extension tcp revision 0 not supported, missing kernel module?
Warning: Extension DNAT revision 0 not supported, missing kernel module?
iptables v1.8.10 (nf_tables):  RULE_APPEND failed (No such file or directory): rule in chain DOCKER

아래의 글을 읽어보면,

리눅스서버 보안 iptables 완벽사용법
; https://www.linux.co.kr/bbs/board.php?bo_table=lecture&wr_id=3746

docker가 하려고 했던 것이 대충 해석이 됩니다.

-t nat: nat 테이블을 대상으로,
-A DOCKER: "Append" 모드로 DOCKER 체인에,
-p tcp: TCP 프로토콜 중,
-d 0/0 --dport 15000: destination으로 "0.0.0.0:15000"으로 지정된 패킷을,
-j DNAT: "Destination NAT"으로 대상을 172.17.0.2:15000으로 전달

현재 설정에 보면 "-A DOCKER"로 지정된 "DOCKER" chain을 확인할 수 있고 기본적으로는 "DROP" 정책이 적용돼 있습니다.

$ sudo iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination
DOCKER-USER  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (1 references)
target     prot opt source               destination

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-USER (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

그렇다면 혹시 FORWARD 체인 전체를 ACCEPT로 바꾸면 되지 않을까요? ^^ 이거저거 건드리기 전에 백업을 좀 해두고,

[백업]
$ sudo iptables-save > /some/file

[복원]
$ sudo iptables-restore > /some/file

다음과 같이 처리했는데,

$ sudo iptables -P FORWARD ACCEPT
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
...[생략]...

아쉽게도 docker run 시 iptables 명령 자체의 실행은 계속하는 바람에 오류는 여전히 발생했습니다.




결국 문제는, 적어도 iptables를 직접 실행했을 때의 오류는 발생해서는 안 되는 것입니다.

자, 그럼 천천히 뜯어볼까요? ^^ 일단 위의 상황을 보면 딱히 iptables 명령어의 옵션이 잘못된 것도 없습니다. 그렇다면, 이제 경고가 눈에 들어오는데요,

Warning: Extension tcp revision 0 not supported, missing kernel module?
Warning: Extension DNAT revision 0 not supported, missing kernel module?

이에 대해 검색해 보면,

iptables comment extension missing
; https://github.com/NixOS/nixpkgs/issues/242853

위의 글은 "comment" extension이 없어 발생한 상황이지만, 답글에 "xt_mark", "xt_comment", "xt_multiport" 3개의 모듈을 올리고 정상적으로 구동됐다는 내용이 있는 것으로 봐서 저 역시 관련 커널 모듈이 없어서 발생한 문제로 보입니다.

그래서, docker가 정상 동작하는 다른 머신에서 커널 모듈을 확인하고,

$ lsmod | grep tables
nf_tables             372736  1891 nft_compat,nft_chain_nat,nft_limit
libcrc32c              12288  3 nf_conntrack,nf_nat,nf_tables
nfnetlink              20480  4 nft_compat,nf_conntrack_netlink,nf_tables
ip6_tables             36864  1 ip6table_filter
arp_tables             28672  0
ip_tables              32768  1 iptable_filter
x_tables               65536  21 ip6table_filter,xt_conntrack,xt_statistic,iptable_filter,nft_compat,xt_LOG,xt_tcpudp,xt_addrtype,xt_CHECKSUM,xt_nat,ip6t_rt,xt_comment,ip6_tables,ipt_REJECT,ip_tables,xt_limit,xt_hl,xt_MASQUERADE,ip6t_REJECT,xt_mark,arp_tables

제 것을 비교해 보면,

$ lsmod | grep tables
nf_tables             221184  55 nft_compat,nft_counter,nft_chain_nat
nfnetlink              20480  4 nft_compat,nf_conntrack_netlink,nf_tables
ip_tables              32768  0
x_tables               49152  5 xt_conntrack,nft_compat,xt_addrtype,ip_tables,xt_MASQUERADE

대충 감으로, "xt_tcpudp", "xt_nat" 모듈이 없어서 발생한 것 같습니다. 테스트를 위해 모듈을 로드하고,

// How to Add, Remove, and Manage Linux Kernel Modules (Drivers)
// ; https://www.cyberciti.biz/faq/add-remove-list-linux-kernel-modules/

$ sudo insmod /usr/lib/modules/5.15.119/kernel/net/netfilter/xt_tcpudp.ko
$ sudo insmod /usr/lib/modules/5.15.119/kernel/net/netfilter/xt_nat.ko

명령어를 실행했더니 잘됩니다. ^^

$ sudo iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 15000 -j DNAT --to-destination 172.17.0.2:15000 ! -i docker0

물론, docker도 잘됩니다.

$ docker run -p 15000:15000 hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.
...[생략]...




insmod로 로드한 커널 모듈은 시스템을 재부팅하면 사라지므로, 영구적으로 로드하기 위해 아래의 글을 따라,

2.10. 시스템 부팅 시 커널 모듈 자동 로드
; https://docs.redhat.com/ko/documentation/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/loading-kernel-modules-automatically-at-system-boot-time_managing-kernel-modules

modules.conf 파일을 이런 식으로 수정했습니다.

$ ll /etc/modules-load.d/modules.conf
lrwxrwxrwx 1 root root 10 Aug  8 23:51 /etc/modules-load.d/modules.conf -> ../modules

$ cat /etc/modules-load.d/modules.conf
...[생략]...
nft_chain_nat
nft_counter
nft_compat
nf_tables
xt_conntrack
xt_MASQUERADE
xt_addrtype
xt_tcpudp
xt_nat
veth

dhd

snd-seq

재부팅하고 다시 살펴보면 끝!

$ sudo reboot now

$ lsmod | grep tables
nf_tables             221184  55 nft_compat,nft_counter,nft_chain_nat
nfnetlink              20480  4 nft_compat,nf_conntrack_netlink,nf_tables
ip_tables              32768  0
x_tables               49152  7 xt_conntrack,nft_compat,xt_tcpudp,xt_addrtype,xt_nat,ip_tables,xt_MASQUERADE

참고로, 저렇게 docker 또는 iptables가 실행된 이후 설정 상태를 보면,

$ sudo iptables --list
...[생략]...

Chain DOCKER (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:ssh

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

...[생략]...

ACCEPT 설정이 DOCKER 체인에 추가된 것을 확인할 수 있습니다.




기타 시행착오로, 아래의 글에서,

Failed to setup IP tables: Unable to enable NAT rule
; https://stackoverflow.com/questions/54380847/failed-to-setup-ip-tables-unable-to-enable-nat-rule

나온 설명대로 따라 해봤으나,

$ sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
$ sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives: using /usr/sbin/ip6tables-legacy to provide /usr/sbin/ip6tables (ip6tables) in manual mode

이후 docker 서비스가 실행되지 않습니다.

$ sudo journalctl -u docker.service
Sep 09 16:28:48 Khadas systemd[1]: Starting docker.service - Docker Application Container Engine...
Sep 09 16:28:49 Khadas dockerd[1210]: time="2024-09-09T16:28:49.309579811+09:00" level=info msg="Starting up"
Sep 09 16:28:49 Khadas dockerd[1210]: time="2024-09-09T16:28:49.320183919+09:00" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using re>
Sep 09 16:28:49 Khadas dockerd[1210]: time="2024-09-09T16:28:49.626823266+09:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Sep 09 16:28:49 Khadas dockerd[1210]: time="2024-09-09T16:28:49.742570336+09:00" level=info msg="Loading containers: start."
Sep 09 16:28:49 Khadas dockerd[1210]: time="2024-09-09T16:28:49.839517543+09:00" level=info msg="unable to detect if iptables supports xlock: 'iptables --wait -L -n': >
Sep 09 16:28:49 Khadas dockerd[1210]: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to register "bridge" d>
Sep 09 16:28:49 Khadas dockerd[1210]: Perhaps iptables or your kernel needs to be upgraded.
Sep 09 16:28:49 Khadas dockerd[1210]:  (exit status 3)
...[생략]...

다시 삭제한 후에야 정상적으로 서비스가 돌아왔습니다.

$ sudo update-alternatives --remove iptables /usr/sbin/iptables-legacy
$ sudo update-alternatives --remove ip6tables /usr/sbin/ip6tables-legacy

$ sudo systemctl start docker




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 9/10/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
13262정성태2/15/202313474디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
13261정성태2/15/202312955Windows: 224. Visual Studio - 영문 폰트가 Fullwidth Latin Character로 바뀌는 문제
13260정성태2/14/202312200오류 유형: 847. ilasm.exe 컴파일 오류 - error : syntax error at token '-' in ... -inf
13259정성태2/14/202312147.NET Framework: 2095. C# - .NET5부터 도입된 CollectionsMarshal
13258정성태2/13/202312896오류 유형: 846. .NET Framework 4.8 Developer Pack 설치 실패 - 0x81f40001
13257정성태2/13/202312316.NET Framework: 2094. C# - Job에 Process 포함하는 방법 [1]파일 다운로드1
13256정성태2/10/202312455개발 환경 구성: 665. WSL 2의 네트워크 통신 방법 - 두 번째 이야기
13255정성태2/10/202312663오류 유형: 845. gihub - windows2022 이미지에서 .NET Framework 4.5.2 미만의 프로젝트에 대한 빌드 오류
13254정성태2/10/202312550Windows: 223. (WMI 쿼리를 위한) PowerShell 문자열 escape 처리
13253정성태2/9/202313700Windows: 222. C# - 다른 윈도우 프로그램이 실행되었음을 인식하는 방법파일 다운로드1
13252정성태2/9/202311588오류 유형: 844. ssh로 명령어 수행 시 멈춤 현상
13251정성태2/8/202312178스크립트: 44. 파이썬의 3가지 스레드 ID
13250정성태2/8/202313762오류 유형: 843. System.InvalidOperationException - Unable to configure HTTPS endpoint
13249정성태2/7/202314363오류 유형: 842. 리눅스 - You must wait longer to change your password
13248정성태2/7/202311035오류 유형: 841. 리눅스 - [사용자 계정] is not in the sudoers file. This incident will be reported.
13247정성태2/7/202312596VS.NET IDE: 180. Visual Studio - 닷넷 소스 코드 디버깅 중 "Decompile source code"가 동작하는 않는 문제
13246정성태2/6/202312427개발 환경 구성: 664. Hyper-V에 설치한 리눅스 VM의 VHD 크기 늘리는 방법 - 두 번째 이야기
13245정성태2/6/202312965.NET Framework: 2093. C# - PKCS#8 PEM 파일을 이용한 RSA 개인키/공개키 설정 방법파일 다운로드1
13244정성태2/5/202312081VS.NET IDE: 179. Visual Studio - External Tools에 Shell 내장 명령어 등록
13243정성태2/5/202313209디버깅 기술: 190. windbg - Win32 API 호출 시점에 BP 거는 방법 [1]
13242정성태2/4/202312063디버깅 기술: 189. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.UnauthorizedAccessException
13241정성태2/3/202310648디버깅 기술: 188. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.IO.FileNotFoundException
13240정성태2/1/202311327디버깅 기술: 187. ASP.NET Web Application (.NET Framework) 프로젝트의 숨겨진 예외 - System.Web.HttpException
13239정성태2/1/202310693디버깅 기술: 186. C# - CacheDependency의 숨겨진 예외 - System.Web.HttpException
13238정성태1/31/202314976.NET Framework: 2092. IIS 웹 사이트를 TLS 1.2 또는 TLS 1.3 프로토콜로만 운영하는 방법
13237정성태1/30/202314281.NET Framework: 2091. C# - 웹 사이트가 어떤 버전의 TLS/SSL을 지원하는지 확인하는 방법
... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...