Q. How can I use my own address space for a NAT network with Windows containers?
A. A default NAT network is created when the Docker daemon starts and with the RTM of Windows Server 2016 only a single NAT network can exist because only one instance of WinNAT is supported on a host that enables the NAT network to function.
There are two options if you don't wish to use the default 172.16.0.0/12 address space the NAT network uses (for example if you use that address space in your normal network).
The first option is to change the address space used by the default NAT network.
- Stop the docker daemon
- Remove the default network
Get-ContainerNetwork | Remove-ContainerNetwork
- Ensure the default switch and WinNAT instance are gone by running Get-VMSwitch and Get-NetNat.
- Edit the daemon.json file in folder C:\ProgramData\docker\config or if it does not exist create the file. For more information on docker configuration see https://msdn.microsoft.com/en-us/virtualization/windowscontainers/docker/configure_docker_daemon.
- In the file add the following JSON but change to match the IP range you wish to use
- Restart docker
The other option is to tell the Docker daemon to not create the default NAT network at all by repeating the steps above but in step 5 the content to be added is:
Now create your own NAT network with the address space you want (note when starting a docker instance you will have to specify which network it will connect to manually):
docker network create -d nat --subnet=192.168.1.0/24 NatNetwork1