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

비밀번호

댓글 작성자
 




[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
13901정성태3/9/2025876Windows: 280. Hyper-V의 3가지 Thread Scheduler (Classic, Core, Root)
13900정성태3/8/20251108스크립트: 72. 파이썬 - SQLAlchemy + oracledb 연동
13899정성태3/7/20251124스크립트: 71. 파이썬 - asyncio의 ContextVar 전달
13898정성태3/5/20251159오류 유형: 948. Visual Studio - Proxy Authentication Required: dotnetfeed.blob.core.windows.net
13897정성태3/5/20251131닷넷: 2326. C# - PowerShell과 연동하는 방법 (두 번째 이야기)파일 다운로드1
13896정성태3/5/20251138Windows: 279. Hyper-V Manager - VM 목록의 CPU Usage 항목이 항상 0%로 나오는 문제
13895정성태3/4/20251276Linux: 117. eBPF / bpf2go - Map에 추가된 요소의 개수를 확인하는 방법
13894정성태2/28/20251396Linux: 116. eBPF / bpf2go - BTF Style Maps 정의 구문과 데이터 정렬 문제
13893정성태2/27/20251402Linux: 115. eBPF (bpf2go) - ARRAY / HASH map 기본 사용법
13892정성태2/24/20251466닷넷: 2325. C# - PowerShell과 연동하는 방법파일 다운로드1
13891정성태2/23/20251433닷넷: 2324. C# - 프로세스의 성능 카운터용 인스턴스 이름을 구하는 방법파일 다운로드1
13890정성태2/21/20251434닷넷: 2323. C# - 프로세스 메모리 중 Private Working Set 크기를 구하는 방법(Win32 API)파일 다운로드1
13889정성태2/20/20251617닷넷: 2322. C# - 프로세스 메모리 중 Private Working Set 크기를 구하는 방법(성능 카운터, WMI) [1]파일 다운로드1
13888정성태2/17/20251371닷넷: 2321. Blazor에서 발생할 수 있는 async void 메서드의 부작용
13887정성태2/17/20251375닷넷: 2320. Blazor의 razor 페이지에서 code-behind 파일로 코드를 분리하는 방법
13886정성태2/15/20251444VS.NET IDE: 196. Visual Studio - Code-behind처럼 cs 파일을 그룹핑하는 방법
13885정성태2/14/20251481닷넷: 2319. ASP.NET Core Web API / Razor 페이지에서 발생할 수 있는 async void 메서드의 부작용
13884정성태2/13/20251856닷넷: 2318. C# - (async Task가 아닌) async void 사용 시의 부작용파일 다운로드1
13883정성태2/12/20251807닷넷: 2317. C# - Memory Mapped I/O를 이용한 PCI Configuration Space 정보 열람파일 다운로드1
13882정성태2/10/20251966스크립트: 70. 파이썬 - oracledb 패키지 연동 시 Thin / Thick 모드
13881정성태2/7/20252063닷넷: 2316. C# - Port I/O를 이용한 PCI Configuration Space 정보 열람파일 다운로드1
13880정성태2/5/20251845오류 유형: 947. sshd - Failed to start OpenSSH server daemon.
13879정성태2/5/20252103오류 유형: 946. Ubuntu - N: Updating from such a repository can't be done securely, and is therefore disabled by default.
13878정성태2/3/20252051오류 유형: 945. Windows - 최대 절전 모드 시 DRIVER_POWER_STATE_FAILURE 발생 (pacer.sys)
13877정성태1/25/20252251닷넷: 2315. C# - PCI 장치 열거 (레지스트리, SetupAPI)파일 다운로드1
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...