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)
13212정성태1/8/202313550기타: 85. 단정도/배정도 부동 소수점의 정밀도(Precision)에 따른 형변환 손실
13211정성태1/6/202313311웹: 42. (https가 아닌) http 다운로드를 막는 웹 브라우저
13210정성태1/5/202312082Windows: 219. 윈도우 x64의 경우 0x00000000`7ffe0000 아래의 주소는 왜 사용하지 않을까요?
13209정성태1/4/202311516Windows: 218. 왜 윈도우에서 가상 메모리 공간은 64KB 정렬이 된 걸까요?
13208정성태1/3/202312364.NET Framework: 2086. C# - Windows 운영체제의 2MB Large 페이지 크기 할당 방법파일 다운로드1
13207정성태12/26/202212834.NET Framework: 2085. C# - gpedit.msc의 "User Rights Assignment" 특권을 코드로 설정/해제하는 방법 [1]파일 다운로드1
13206정성태12/24/202212996.NET Framework: 2084. C# - GetTokenInformation으로 사용자 SID(Security identifiers) 구하는 방법 [4]파일 다운로드1
13205정성태12/24/202212188.NET Framework: 2083. C# - C++과의 연동을 위한 구조체의 fixed 배열 필드 사용 (2)파일 다운로드1
13204정성태12/22/202211365.NET Framework: 2082. C# - (LSA_UNICODE_STRING 예제로) CustomMarshaler 사용법파일 다운로드1
13203정성태12/22/202211788.NET Framework: 2081. C# Interop 예제 - (LSA_UNICODE_STRING 예제로) 구조체를 C++에 전달하는 방법파일 다운로드1
13202정성태12/21/202213141기타: 84. 직렬화로 설명하는 Little/Big Endian파일 다운로드1
13201정성태12/20/202214248오류 유형: 835. PyCharm 사용 시 C 드라이브 용량 부족
13200정성태12/19/202212230오류 유형: 834. 이벤트 로그 - SSL Certificate Settings created by an admin process for endpoint
13199정성태12/19/202212294개발 환경 구성: 656. Internal Network 유형의 스위치로 공유한 Hyper-V의 VM과 호스트가 통신이 안 되는 경우
13198정성태12/18/202212524.NET Framework: 2080. C# - Microsoft.XmlSerializer.Generator 처리 없이 XmlSerializer 생성자를 예외 없이 사용하고 싶다면?파일 다운로드1
13197정성태12/17/202212051.NET Framework: 2079. .NET Core/5+ 환경에서 XmlSerializer 사용 시 System.IO.FileNotFoundException 예외 발생하는 경우파일 다운로드1
13196정성태12/16/202212670.NET Framework: 2078. .NET Core/5+를 위한 SGen(Microsoft.XmlSerializer.Generator) 사용법
13195정성태12/15/202213023개발 환경 구성: 655. docker - bridge 네트워크 모드에서 컨테이너 간 통신 시 --link 옵션 권장 이유
13194정성태12/14/202213283오류 유형: 833. warning C4747: Calling managed 'DllMain': Managed code may not be run under loader lock파일 다운로드1
13193정성태12/14/202213428오류 유형: 832. error C7681: two-phase name lookup is not supported for C++/CLI or C++/CX; use /Zc:twoPhase-
13192정성태12/13/202213349Linux: 55. 리눅스 - bash shell에서 실수 연산
13191정성태12/11/202215271.NET Framework: 2077. C# - 직접 만들어 보는 SynchronizationContext파일 다운로드1
13190정성태12/9/202216753.NET Framework: 2076. C# - SynchronizationContext 기본 사용법파일 다운로드1
13189정성태12/9/202216879오류 유형: 831. Visual Studio - Windows Forms 디자이너의 도구 상자에 컨트롤이 보이지 않는 문제
13188정성태12/9/202215295.NET Framework: 2075. C# - 직접 만들어 보는 TaskScheduler 실습 (SingleThreadTaskScheduler)파일 다운로드1
13187정성태12/8/202215275개발 환경 구성: 654. openssl - CA로부터 인증받은 새로운 인증서를 생성하는 방법 (2)
... 16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  ...