6. Restart Docker.
start-service docker
The default WinNAT instance will now be using your custom IP range as will the
created NAT network.
The other option is to suppress the automatic creation of the default NAT network and
then create your own NAT network by using the commands covered at the start of this
section. To suppress the automatic creation of the default NAT network, perform the
same steps, but replace the code to be added in step 4 with the following:
{
"bridge": "none"
}
Note that if you create a user-defined network, you will have to specify which network
the container endpoint should attach to by using the - -network=
the docker run command.
The key point here is that in most environments, the default NAT network is all you
need, and no manual actions should be required. Only if you need to use a different IP
space should you perform one of the preceding actions, but in no circumstances
should you try to add additional NAT networks to the default. There is a pull request
(PR) in GitHub related to enabling multiple NAT networks, provided they are a subset
of the default WinNAT IP range ( 172. 16. 0. 0 / 12 ). This will likely be available by the
time you read this, and I expect in future branches of Windows Server there to be
support for multiple WinNAT instances, but that would not be until 2017 at the
earliest.
If you want the container to offer services when using NAT, it needs to do this by
using port-forwarding rules on the IP address of the container host. These are known
as endpoints. I cover adding endpoints when creating container instances later in this
chapter, but it essentially consists of adding a port mapping as part of the Docker run
command by using - p
8080 : 80 would map port 8080 on the container IP to port 80 on the container.
If you find that you have gotten yourself into a strange situation, to reset your
networking for containers and wipe any containers, use the following:
Get-Container | Stop-Container
Get-Container | Remove-Container - Force
Get-ContainerNetwork | Remove-ContainerNetwork - Force
Stop-Service docker
DEPLOYING A TRANSPARENT NETWORK
Deploying a transparent network is simple, as it consists of adding a new external
vSwitch and creating the network so that it’s available to containers. To create a
transparent network, use the following: