Understanding container networking
By default, containers attach to a network nameddefault which provides:
- IP address allocation
- DNS resolution for container names
- Communication between containers on the same network
- Network isolation from other networks
Running
container system start creates a vmnet network named default to which your containers will attach unless you specify otherwise.Publishing ports
Use the--publish (or -p) option to forward TCP or UDP traffic from your loopback IP to the container.
Basic port publishing
The option format is:[host-ip:]host-port:container-port[/protocol]
Publishing to specific interfaces
- IPv4 loopback
- IPv6 loopback
Forward requests from port 8080 on the IPv4 loopback IP to container port 8000:Test access:
Publishing UDP ports
The protocol may be
tcp or udp (case insensitive). TCP is the default if not specified.Multiple port mappings
If your container attaches to multiple networks, the ports you publish forward to the IP address of the interface attached to the first network.
Accessing containers directly
Containers receive IP addresses and can be accessed directly from the host without port publishing.Using IP addresses
Using DNS names
With DNS configured, containers are accessible by name:DNS configuration
Setting up a local DNS domain
Create a local DNS domain for container name resolution:The first command requires administrator privileges to create a file under
/etc/resolver and reload the macOS DNS resolver configuration.test the default domain. For example, if you use --name my-web-server, queries to my-web-server.test will respond with that container’s IP address.
Listing DNS domains
Deleting DNS domains
Custom DNS configuration
You can override DNS settings for individual containers:- DNS options
--dns: DNS nameserver IP address (can be specified multiple times)--dns-domain: Default DNS domain--dns-search: DNS search domains (can be specified multiple times)--dns-option: DNS resolver options--no-dns: Disable DNS configuration in the container
Creating custom networks
This feature is available on macOS 26 and later.
container network create.
Basic network creation
Custom subnets
Specify custom IPv4 and IPv6 subnets:When creating a network without explicit subnet options, the system uses default values if configured via system properties, or automatically allocates subnets. The system validates that custom subnets don’t overlap with existing networks.
Configuring default subnets
Set default IPv4 and IPv6 subnets for new networks:--subnet or --subnet-v6 options.
Working with networks
Listing networks
Inspecting networks
Attaching containers to networks
The
foo network, the default network, and any other networks you create are isolated from one another. A container on one network has no connectivity to containers on other networks.Deleting networks
You can delete networks once no containers are attached:Pruning unused networks
Remove networks not connected to any containers:Default and system networks are preserved during pruning.
Network isolation
Containers on different networks cannot communicate with each other:container-a and container-b have no connectivity to each other.
Network isolation is enforced at the network layer. Use separate networks to isolate different application environments or security zones.
Container-to-container communication
Containers on the same network can communicate directly using IP addresses or DNS names.Using DNS names
Container-to-container networking relies on features present in macOS 26. This functionality will not work on macOS 15. See the technical overview for more details.
Accessing host services from containers
Create a DNS domain with--localhost <ipv4-address> to make a domain used by a container to access a host service.
Setting up host access
Create a DNS domain for host connection
Choose an IP address that is least likely to conflict with any networks. Reasonably safe address ranges include:
- Documentation ranges: 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24
- Private range: 172.16.0.0/12
Custom MAC addresses
Use themac option to specify a custom MAC address for your container’s network interface.
Setting a MAC address
The MAC address must be in the format
XX:XX:XX:XX:XX:XX (with colons or hyphens). Set the two least significant bits of the first octet to 10 (locally signed, unicast address).Verifying the MAC address
If you don’t specify a MAC address,
container will generate one for you. Generated addresses have a first nibble set to hexadecimal f (fX:XX:XX:XX:XX:XX) to minimize conflicts with custom addresses.Use cases
Network testing scenarios
Custom MAC addresses are useful for:- Network testing scenarios requiring predictable MAC addresses
- Consistent network configuration across container restarts
- License systems tied to MAC addresses