InfraPlatform

How to Start WSL - Ubuntu - docker 실행 iptables-legacy로 전환 해결

IT오이시이 2024. 3. 21. 00:02
728x90

 

 

 

 


WSL사용법- How To Start WSL

 

 


 
 

 

 

How to Start WSL - Ubuntu - docker 실행 iptables-legacy로 전환 해결

 -- "docker : iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN" 오류 해결 --

 

우분투 22.04 버전이후 WSL 설치하는 경우 : ‘iptables-legacy’를 사용

  우분투 22.04 버전이후 WSL 설치하는 경우  ‘iptables-nft’가 기본 설정으로 잡혀있어서, WSL에서 도커를 사용할 때 호환성 이슈가 발생합니다. ‘iptables-nft’ 대신 ‘iptables-legacy’를 사용해야 도커 데몬을 실행할 수 있습니다.

Failure to install and run Docker in WSL Ubuntu 22.04 (works in 20.04): “Cannot connect to the Docker daemon” [https://github.com/docker/for-linux/issues/1406]

 

 iptables 호환성 문제로 도커가 작동되지 않는 문제를 해결하는 방법입니다.

증상 :   iptables failed 문제로 Docker 설치후 작동이 되지 않고 있습니다.
 
원인은 
"iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN" 오류로  iptables filter 테이블에서 호환되지 않는다는 메시지와 함께  nft 도구 사용을 권장하고 있습니다.

이 문제를 해결하기 위해 몇 가지 단계를 정리해 봅니다.

iptables  관련 경고 메시지를 통해, 시스템이 iptables-legacy 를 사용하고 있으며, iptables 버전(1.8.7, nf_tables 기반)이 이와 호환되지 않는 문제로 파악 됩니다.

 

Docker를 설치하고 작동이 되지 않는 문제가 발생하는 경우 docker.log를 보고 해결 방안을 정리하였습니다.

 

1. 도커 설치 방법

   도커 설치는 아래 글을 참조 바랍니다.

    [InfraPlatform] - How to Start WSL - docker 설치하기

 

2. 도커 서비스 실행과 종료

  도커를 실행하는 방법은 service 명령을 이용해서 도커를 실행하고 종료 할 수 있습니다.

# 도커 서비스 실행
$ sudo service docker start

# 도커 서비스 확인
$ sudo service docker status


# 도커 서비스 종료
$ sudo service docker stop

 

 

3. 도커 실행이 되지 않고 계속 종료 되는 문제 발견

아래와 같이 도커를 실행하고 'docker.log'를 tail로 보면 도커 서비스가 실행되지 않고 종료되는 현상이 발견됩니다.

# 도커 로그를 로깅합니다.
$sudo tail -f /var/log/docker.log &


# 도커를 실행합니다.
$sudo service docker start

 

"iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1.8.7 (nf_tables)" 오류는 iptables의 호환성 문제로 파악이 됩니다. 

현재 iptables 버전(1.8.7, nf_tables 기반)이 이와 호환되지 않는 문제가 보입니다.

time="2024-03-17T14:06:32.769818088+09:00" level=info msg="Loading containers: start."
time="2024-03-17T14:06:32.931987364+09:00" level=info msg="stopping event stream following gra              ceful shutdown" error="<nil>" module=libcontainerd namespace=moby
time="2024-03-17T14:06:32.932277926+09:00" level=info msg="stopping healthcheck following grac              eful shutdown" module=libcontainerd
time="2024-03-17T14:06:32.932278148+09:00" level=info msg="stopping event stream following gra              ceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
failed to start daemon: Error initializing network controller: error obtaining controller inst              ance: failed to register "bridge" driver: unable to add return rule in DOCKER-ISOLATION-STAGE-              1 chain:  (iptables failed: iptables --wait -A DOCKER-ISOLATION-STAGE-1 -j RETURN: iptables v1              .8.7 (nf_tables):  RULE_APPEND failed (No such file or directory): rule in chain DOCKER-ISOLAT              ION-STAGE-1
 (exit status 4))

 

4. iptables-legacy 전환 

 

시스템이 iptables-nft와 iptables-legacy 중 어느 것을 사용하고 있는지 확인하고, 필요하다면 iptables-legacy로 전환할 수 있습니다. 이는 일부 시스템과 Docker 버전에서 호환성 문제를 해결할 수 있습니다.

 

#현재 사용 중인 iptables 버전 확인
sudo update-alternatives --display iptables

#iptables를 iptables-legacy로 전환
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

#iptables 설정 조회
sudo iptables -L

 

 

5. docker 작동과 확인

아래와 같이 도커를 실행하면 로그파일에 정상 작동 상태를 확인 가능합니다.

 

# 도커 로그를 로깅합니다.
$sudo tail -f /var/log/docker.log &


# 도커를 실행합니다.
$sudo service docker start

#도커 실행 상태를 확인합니다.
$sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
time="2024-03-19T01:15:12.315591222+09:00" level=info msg="Loading containers: start."
time="2024-03-19T01:15:13.643578308+09:00" level=info msg="Loading containers: done."
time="2024-03-19T01:15:13.656575770+09:00" level=warning msg="WARNING: No blkio throttle.read_bps_device support"
time="2024-03-19T01:15:13.656600666+09:00" level=warning msg="WARNING: No blkio throttle.write_bps_device support"
time="2024-03-19T01:15:13.656604468+09:00" level=warning msg="WARNING: No blkio throttle.read_iops_device support"
time="2024-03-19T01:15:13.656607269+09:00" level=warning msg="WARNING: No blkio throttle.write_iops_device support"
time="2024-03-19T01:15:13.656619378+09:00" level=info msg="Docker daemon" commit=061aa95 containerd-snapshotter=false storage-driver=overlay2 version=25.0.4
time="2024-03-19T01:15:13.657221785+09:00" level=info msg="Daemon has completed initialization"
time="2024-03-19T01:15:13.679477693+09:00" level=info msg="API listen on /var/run/docker.sock"

 

 

6. iptables 작동 확인

아래와 같이 iptables의 룰도 정상적으로 작동됨을 확인 할 수 있습니다.

 

$sudo iptables -L
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

 

 

감사합니다.

728x90
반응형