环境说明;
在Docker容器中
操作:
sudo iptables -L -n
说明:docker默认使用的是Ubuntu操作系统。所以,上面命令是Ubuntu查看iptables命令。
出现的情况:
iptables v1.4.21: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
问题原因:
iptables 必须是root用户执行
iptables 必须在容器的特权模式(privileged)下执行
解决
在命令中添加 --privileged 参数既可以。
方式一:
运行容器时添加privileged
docker run --privileged xxx
xxx可以是容器的id或容器的名字
方式二:
或进入容器是添加privileged
docker exec -it --privileged xxx
这里凯哥(微信公众号:凯哥Java(kaigejava))就使用方式二。
添加--privilege命令后,就可以正常查看了