Docker Community Forums

Share and learn in the Docker community.

How to change NAT method to Route method when using command "docker network create ..."

Hello Dear,

I was trying to use the following command to crate a docker container network without NAT.

docker network create --driver=bridge --subnet=172.18.121.0/24 --gateway=172.18.121.1 --opt ip-masq=false br0

Then I was trying to disable iptables when starting docker daemon, my way is to add a file named "daemon.json" located in directory "/etc/docker/".

[root@wenca-centos121 ~]# vi /etc/docker/daemon.json
{
“debug”: true,
“iptables”: false
}

I am hoping that my external device like a Router can directly access to my container running on CENTOS 7. 

However it failed when I view iptables nat table.

[root@wenca-centos121 ~]# iptables -t nat -L POSTROUTING
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all – 172.18.121.0/24 anywhere

Below are my host and docker configuration and info. Did someone meet it? Thanks.

[root@wenca-centos121 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

[root@wenca-centos121 ~]# docker version
Server: Docker Engine - Community
Engine:
Version: 18.09.6
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:02:43 2019
OS/Arch: linux/amd64
Experimental: false

[root@wenca-centos121 ~]# cat /etc/docker/daemon.json
{
“debug”: true,
“iptables”: false
}

[root@wenca-centos121 ~]# docker network inspect br0
[
{
“Name”: “br0”,
“Id”: “525e2b3050ed78866992743a3835fd8bf7aec02280773bb29237336793d8fc69”,
“Created”: “2019-06-05T16:19:31.158582937+08:00”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: {},
“Config”: [
{
“Subnet”: “172.18.121.0/24”,
“Gateway”: “172.18.121.1”
}
]
},
“Internal”: false,
“Attachable”: false,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“ce446c11eb3718502bb61b50d0048f7c6962e1f8ae1484a9f0c45ad68433cd10”: {
“Name”: “zealous_brattain”,
“EndpointID”: “22f91be5acb3c8e2779bc980021ee8946755b96fc6f637d2071aa17a54425306”,
“MacAddress”: “02:42:ac:12:79:02”,
“IPv4Address”: “172.18.121.2/24”,
“IPv6Address”: “”
}
},
“Options”: {
“ip-masq”: “false”
},
“Labels”: {}
}
]