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)
13287정성태3/16/202311599Windows: 229. Win32 - 대화창 템플릿의 2진 리소스를 읽어들여 윈도우를 직접 띄우는 방법파일 다운로드1
13286정성태3/15/202312023Windows: 228. Win32 - 리소스에 포함된 대화창 Template의 2진 코드 해석 방법
13285정성태3/14/202311407Windows: 227. Win32 C/C++ - Dialog Procedure를 재정의하는 방법 [2]파일 다운로드1
13284정성태3/13/202311279Windows: 226. Win32 C/C++ - Dialog에서 값을 반환하는 방법파일 다운로드1
13283정성태3/12/202310105오류 유형: 852. 파이썬 - TypeError: coercing to Unicode: need string or buffer, NoneType found
13282정성태3/12/202310496Linux: 58. WSL - nohup 옵션이 필요한 경우
13281정성태3/12/202311142Windows: 225. 윈도우 바탕화면의 아이콘들이 넓게 퍼지는 경우 [2]
13280정성태3/9/202312627개발 환경 구성: 670. WSL 2에서 호스팅 중인 TCP 서버를 외부에서 접근하는 방법
13279정성태3/9/202312087오류 유형: 851. 파이썬 ModuleNotFoundError: No module named '_cffi_backend'
13278정성태3/8/202311888개발 환경 구성: 669. WSL 2의 (init이 아닌) systemd 지원 [1]
13277정성태3/6/202313161개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/202312761.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어 [1]
13275정성태3/3/202312674.NET Framework: 2101. C# 11의 ref 필드 설명
13274정성태3/2/202311946.NET Framework: 2100. C# - ref 필드로 ref struct 타입을 허용하지 않는 이유
13273정성태2/28/202310968.NET Framework: 2099. C# - 관리 포인터로서의 ref 예약어 의미
13272정성태2/27/202311838오류 유형: 850. SSMS - mdf 파일을 Attach 시킬 때 Operating system error 5: "5(Access is denied.)" 에러
13271정성태2/25/202311655오류 유형: 849. Sql Server Configuration Manager가 시작 메뉴에 없는 경우
13270정성태2/24/202310934.NET Framework: 2098. dotnet build에 /p 옵션을 적용 시 유의점
13269정성태2/23/202312318스크립트: 46. 파이썬 - uvicorn의 콘솔 출력을 UDP로 전송
13268정성태2/22/202312754개발 환경 구성: 667. WSL 2 내부에서 열고 있는 UDP 서버를 호스트 측에서 접속하는 방법
13267정성태2/21/202313087.NET Framework: 2097. C# - 비동기 소켓 사용 시 메모리 해제가 finalizer 단계에서 발생하는 사례파일 다운로드1
13266정성태2/20/202312394오류 유형: 848. .NET Core/5+ - Process terminated. Couldn't find a valid ICU package installed on the system
13265정성태2/18/202312804.NET Framework: 2096. .NET Core/5+ - PublishSingleFile 유형에 대한 runtimeconfig.json 설정
13264정성태2/17/202314768스크립트: 45. 파이썬 - uvicorn 사용자 정의 Logger 작성
13263정성태2/16/202312083개발 환경 구성: 666. 최신 버전의 ilasm.exe/ildasm.exe 사용하는 방법
13262정성태2/15/202313474디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
... 16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  ...