[Solved] Centos7 Install docker Error: iptables v1.4.21: Couldn‘t load target `DOCKER-ISOLATION‘

Recently, in the process of learning docker, I encountered problems when I started docker in the first step. After the installation is completed according to the steps on the official website, I started it and reported an error: iptables v1.4.21: Couldn’t load target `DOCKER-ISOLATION’, as follows:

 2022-07-01 06:18:25 ERROR: INVALID_TYPE: structure size mismatch 16 != 13
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -C FORWARD -j DOCKER-ISOLATION' failed: iptables v1.4.21: Couldn't load target `DOCKER-ISOLATION':No such file or directory
                                     
                                     Try `iptables -h' or 'iptables --help' for more information.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -D PREROUTING -m addrtype --dst-type LOCAL -j DOCKER' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -D OUTPUT -m addrtype --dst-type LOCAL ! --dst 127.0.0.0/8 -j DOCKER' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -D OUTPUT -m addrtype --dst-type LOCAL -j DOCKER' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -D PREROUTING' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -D OUTPUT' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -F DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -X DOCKER-ISOLATION' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -n -L DOCKER' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -n -L DOCKER' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -n -L DOCKER-ISOLATION-STAGE-1' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -n -L DOCKER-ISOLATION-STAGE-2' failed: iptables: No chain/target/match by that name.
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -C DOCKER-ISOLATION-STAGE-1 -j RETURN' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t filter -C DOCKER-ISOLATION-STAGE-2 -j RETURN' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -C DOCKER -i docker0 -j RETURN' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: INVALID_ZONE: docker
Jul 01 06:18:25 root dockerd[3099]: time="2022-07-01T06:18:25.949084585-04:00" level=warning msg="could not create bridge network for id c16a1afb8269e0c2975e1fa4f83afa877f5a6892b583196c54dc6b4936644d42 bridge name docker0 while booting up from persi
Jul 01 06:18:25 root dockerd[3099]: time="2022-07-01T06:18:25.964995921-04:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Jul 01 06:18:25 root firewalld[917]: 2022-07-01 06:18:25 ERROR: COMMAND_FAILED: '/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).
Jul 01 06:18:26 root firewalld[917]: 2022-07-01 06:18:26 ERROR: INVALID_ZONE: docker
Jul 01 06:18:26 root dockerd[3099]: time="2022-07-01T06:18:26.028214802-04:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
Jul 01 06:18:26 root dockerd[3099]: failed to start daemon: Error initializing network controller: Error creating default "bridge" network: Failed to program NAT chain: INVALID_ZONE: docker
Jul 01 06:18:26 root systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Jul 01 06:18:26 root systemd[1]: Failed to start Docker Application Container Engine.

At first, turn off the firewall and it can really start

systemctl stop firewalld

But I always feel that the problem is not here. After searching, it is found that in centos7, firewall is used instead of iptables. To solve this problem, turn off firewall and enable iptables

# Turn off the firewall
systemctl stop firewalld
 
# Disable boot up
systemctl disable firewalld

# Install iptables
yum install iptables-services -y

# Restart the firewall to make the configuration take effect
systemctl restart iptables
 
# Set the firewall to boot up
systemctl enable iptables

Problem solving! Record it for future study

Read More: