1Jan

Docker For Mac Docker Subnet

1 Jan 2000admin
Docker For Mac Docker Subnet 4,4/5 3243 votes

Any Docker for Mac user here? I'm trying to deploy multiple services from a docker-compose.yml file that are sharing the same user-defined bridge network (this is from the mailcow-dockerized config). Services are communicating with each-others just fine, but they can't reach internet.

-->

In addition to leveraging the default 'nat' network created by Docker on Windows, users can define custom container networks. User-defined networks can be created using the Docker CLI docker network create -d <NETWORK DRIVER TYPE> <NAME> command. On Windows, the following network driver types are available:

  • nat – containers attached to a network created with the 'nat' driver will be connected to an internal Hyper-V switch and receive an IP address from the user-specified (--subnet) IP prefix. Port forwarding / mapping from the container host to container endpoints is supported.

    Note

    NAT networks created on Windows Server 2019 (or above) are no longer persisted after reboot.

    Multiple NAT networks are supported if you have the Windows 10 Creators Update installed (or above).

  • transparent – containers attached to a network created with the 'transparent' driver will be directly connected to the physical network through an external Hyper-V switch. IPs from the physical network can be assigned statically (requires user-specified --subnet option) or dynamically using an external DHCP server.

    Note

    Due to the following requirement, connecting your container hosts over a transparent network is not supported on Azure VMs.

    Requires: When this mode is used in a virtualization scenario (container host is a VM) MAC address spoofing is required.

  • overlay - when the docker engine is running in swarm mode, containers attached to an overlay network can communicate with other containers attached to the same network across multiple container hosts. Each overlay network that is created on a Swarm cluster is created with its own IP subnet, defined by a private IP prefix. The overlay network driver uses VXLAN encapsulation. Can be used with Kubernetes when using suitable network control planes (e.g. Flannel).

    Requires: Make sure your environment satisfies these required prerequisites for creating overlay networks.

    Requires: On Windows Server 2019, this requires KB4489899.

    Requires: On Windows Server 2016, this requires KB4015217.

    Note

    On Windows Server 2019, overlay networks created by Docker Swarm leverage VFP NAT rules for outbound connectivity. This means that a given container receives 1 IP address. It also means that ICMP-based tools such as ping or Test-NetConnection should be configured using their TCP/UDP options in debugging situations.

  • l2bridge - similar to transparent networking mode, containers attached to a network created with the 'l2bridge' driver will be connected to the physical network through an external Hyper-V switch. The difference in l2bridge is that container endpoints will have the same MAC address as the host due to Layer-2 address translation (MAC re-write) operation on ingress and egress. In clustering scenarios, this helps alleviate the stress on switches having to learn MAC addresses of sometimes short-lived containers. L2bridge networks can be configured in 2 different ways:

    1. L2bridge network is configured with the same IP subnet as the container host
    2. L2bridge network is configured with a new custom IP subnet

    In configuration 2 users will need to add a endpoint on the host network compartment that acts as a gateway and configure routing capabilities for the designated prefix.

    Requires: Requires Windows Server 2016, Windows 10 Creators Update, or a later release.

  • l2bridge - similar to transparent networking mode, containers attached to a network created with the 'l2bridge' driver will be connected to the physical network through an external Hyper-V switch. The difference in l2bridge is that container endpoints will have the same MAC address as the host due to Layer-2 address translation (MAC re-write) operation on ingress and egress. In clustering scenarios, this helps alleviate the stress on switches having to learn MAC addresses of sometimes short-lived containers. L2bridge networks can be configured in 2 different ways:

    1. L2bridge network is configured with the same IP subnet as the container host
    2. L2bridge network is configured with a new custom IP subnet

    In configuration 2 users will need to add a endpoint on the host network compartment that acts as a gateway and configure routing capabilities for the designated prefix.

    Tip

    More details on how to configure and install l2bridge can be found here.

  • l2tunnel - Similar to l2bridge, however this driver should only be used in a Microsoft Cloud Stack (Azure). Packets coming from a container are sent to the virtualization host where SDN policy is applied.

Network topologies and IPAM

The table below shows how network connectivity is provided for internal (container-to-container) and external connections for each network driver.

Networking modes/Docker drivers

Docker Windows Network DriverTypical usesContainer-to-container (Single node)Container-to-external (single node + multi-node)Container-to-container (multi-node)
NAT (Default)Good for Developers
  • Same Subnet: Bridged connection through Hyper-V virtual switch
  • Cross subnet: Not supported (only one NAT internal prefix)
Routed through Management vNIC (bound to WinNAT)Not directly supported: requires exposing ports through host
TransparentGood for Developers or small deployments
  • Same Subnet: Bridged connection through Hyper-V virtual switch
  • Cross Subnet: Routed through container host
Routed through container host with direct access to (physical) network adapterRouted through container host with direct access to (physical) network adapter
OverlayGood for multi-node; required for Docker Swarm, available in Kubernetes
  • Same Subnet: Bridged connection through Hyper-V virtual switch
  • Cross Subnet: Network traffic is encapsulated and routed through Mgmt vNIC
Not directly supported - requires second container endpoint attached to NAT network on Windows Server 2016 or VFP NAT rule on Windows Server 2019.Same/Cross Subnet: Network traffic is encapsulated using VXLAN and routed through Mgmt vNIC
L2BridgeUsed for Kubernetes and Microsoft SDN
  • Same Subnet: Bridged connection through Hyper-V virtual switch
  • Cross Subnet: Container MAC address re-written on ingress and egress and routed
Container MAC address re-written on ingress and egress
  • Same Subnet: Bridged connection
  • Cross Subnet: routed through Mgmt vNIC on WSv1809 and above
L2TunnelAzure onlySame/Cross Subnet: Hair-pinned to physical host's Hyper-V virtual switch to where policy is appliedTraffic must go through Azure virtual network gatewaySame/Cross Subnet: Hair-pinned to physical host's Hyper-V virtual switch to where policy is applied

IPAM

IP Addresses are allocated and assigned differently for each networking driver. Windows uses the Host Networking Service (HNS) to provide IPAM for the nat driver and works with Docker Swarm Mode (internal KVS) to provide IPAM for overlay. All other network drivers use an external IPAM.

Networking Mode / DriverIPAM
NATDynamic IP allocation and assignment by Host Networking Service (HNS) from internal NAT subnet prefix
TransparentStatic or dynamic (using external DHCP server) IP allocation and assignment from IP addresses within container host's network prefix
OverlayDynamic IP allocation from Docker Engine Swarm Mode managed prefixes and assignment through HNS
L2BridgeStatic IP allocation and assignment from IP addresses within container host's network prefix (could also be assigned through HNS)
L2TunnelAzure only - Dynamic IP allocation and assignment from plugin

Service Discovery

Service Discovery is only supported for certain Windows network drivers.

Local Service DiscoveryGlobal Service Discovery
natYESYES with Docker EE
overlayYESYES with Docker EE or kube-dns
transparentNONO
l2bridgeNOYES with kube-dns

The platform known as Docker has become one of the most popular ways to run a new kind of software known as containerized apps. And while Docker's mainly aimed at programmer types, there are a few reasons why everyday Mac users might want it around as well.

What are containerized apps?

Containerized apps are tidy little packages of software that bundle nearly everything they need to run in a single, self-contained box.

Programmers can write an app once and know that it'll run anywhere, every time. Businesses get an efficient way to run lots of apps on a single server without straining their hardware. And users get apps that won't sprawl out and spread files into their hard drives' nooks and crannies, nor start hogging memory and slowing down the entire computer.

How does Docker work?

Docker uses emulation to ensure that the same containerized app can run on any machine where Docker's installed. And because it emulates an operating system – usually some flavor of Linux, though you can also set it up to run enterprise versions of Windows – instead of actual chip hardware, it demands a lot less memory and processing power than traditional virtual machines like Parallels or VMware Fusion.

Unlike those apps, you can't use Docker to run Windows on your Mac – though you can run at least limited versions of Linux with it. And you can use Docker to run apps that weren't originally written for the Mac.

Once you fire up the easy-to-install Docker app, it runs in the background, and you can use the Terminal or another app called Kitematic (we'll get to that later) to install and run containerized apps.

Who is Docker for?

As mentioned above, Docker's mainly aimed at programmers who want to containerize existing apps or write new ones, and businesses and IT folks who want to use its industrial-grade software.

There are Docker versions of familiar desktop apps like Firefox, Chrome, Skype, Spotify, image editor GiMP, and audio editor Audacity. But most of these apps already have native Mac versions. Running them in containers only makes sense if you like the technical challenge, want to keep a single app from hogging all your system's memory, or want to ensure that any malware you might pick up while browsing the web stays stuck inside its container, unable to escape to the rest of your Mac.

As of this writing, the main reason I've found to run Docker on a Mac is Pi-hole, originally made for the Raspberry Pi. Pi-hole can automatically block Web ads across your entire home network, and Docker's the only way to get it working on a Mac without also having a Raspberry Pi.

How to install Docker on your Mac

1. Create a Docker Hub account

Docker Hub keeps track of the containers you're running (or creating) and provides a one-stop shop to find new ones. Sign up for a Docker account with a unique Docker ID, your email, and a strong password.

2. Download Docker Desktop for Mac

Once you've signed up and signed in to Docker Hub, get Docker Desktop for Mac. It's got everything you'll need to run Docker in one Mac-friendly installer. Your Mac needs to be running Mac OS Sierra or later, and have at least 4GB of RAM.

3. Install Docker Desktop on your Mac

Not

Open the docker.dmg file you downloaded, and drag the Docker app's cartoon whale icon into your Applications folder.

4. Open and run Docker

When you run the Docker app, a little whale icon will appear on the right side of the menubar atop your screen. It'll take a few minutes to get running, and Docker may ask your permission to use services on your computer. The app will also prompt you to enter the Docker ID and password you just created.

When containers stop appearing and disappearing atop the little whale icon in the menubar, and you see a green dot at the top of the Docker menu next to 'Docker Desktop is running,' you're all set.

Consult the Preferences in the Docker menu to control how big a chunk of your hard drive Docker's allotted, and how much of your memory and CPU it's allowed to use, among other options.

5. Download and install Kitematic

Kitematic lets you install, manage, and remove your Docker containers from a single graphical interface — a lifesaver if you're not familiar or comfortable with the Terminal. You can install, and later open, Kitematic directly from the Docker app's menu:

Follow the link in that dialog box to install Kitematic. The app may ask for — you guessed it — your Docker ID and password again, just to keep track of your containers.

From Kitematic, you can search for and install new containers, and delete, edit, stop, or restart existing ones. If a container's running, Kitematic gives you an easy way to view its log files, which aren't readily visible from the Terminal. Anyconnect vpn client is not compatible with parallels desktop for mac free. The interface is fairly intuitive, so feel free to play around and see what you can do.

In my tests, Kitematic came in most useful for deleting troublesome containers whose installation I'd somehow botched. Just find the container in the list on the left side of the Kitematic window, click the X icon next to it, and the container's gone completely, for good. You can always reinstall a package, either from the Terminal or by searching for it in Kitematic, and try again.

Where can I learn more about Docker for Mac?

Consult Docker for Mac's help files for more information about getting started, ways to test that your installation's up and running smoothly, and more things you can do with Docker. There's also a guide to teach you how to create your own containerized apps.

For less technically inclined folks, it's tough to find a good list of desktop apps that work with Docker. Docker Hub doesn't break desktop apps into their own category, but Jessie Frazelle compiled this list in 2015.

Besides Pi-hole, do you have any favorite Docker containers that might benefit everyday Mac users? Ship them our way in the comments below.

macOS Catalina

Main

U.S. and Afghan forces successfully captured insurgents using an iPhone app

When their specialist kit failed, soldiers turned to an iPhone to get the job done.