Skip to content

Commit a39525d

Browse files
committed
docs: consolidate DNS domain setup explanation into networking.md
DNS setup was split across three docs, each describing only one of the two required steps. Give it one canonical walkthrough in networking.md's new "Set up DNS-based container names" section, and trim the other docs to link there instead of re-deriving it. Also fixes a stale `container network list` example. Signed-off-by: Eric Ernst <eric_ernst@apple.com>
1 parent dcea825 commit a39525d

4 files changed

Lines changed: 97 additions & 14 deletions

File tree

docs/container-system-config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Defaults applied when `container run` / `container create` is invoked without `-
5050
|----------|-----------|---------|----------------------------------------------------------------------------|
5151
| `domain` | `String?` | unset | Local DNS domain appended to container hostnames (e.g. `"test"` makes `my-web-server` resolvable as `my-web-server.test`). When unset, no domain is appended. |
5252

53+
Setting `domain` here tells the `container` service what domain to register container
54+
hostnames under. See [Networking: Set up DNS-based container
55+
names](./networking.md#set-up-dns-based-container-names) for the full walkthrough.
56+
5357
## `[kernel]`
5458

5559
Guest kernel used when launching container VMs. Defaults change per release as kernels are bumped — check the [source](../Sources/ContainerPersistence/ContainerSystemConfig.swift) for current values.

docs/networking.md

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,83 @@
33
Learn how `container` networks containers with one another, with the host, and with
44
external systems.
55

6-
## Overview
7-
86
Running `container system start` creates a vmnet network named `default`, to which your
9-
containers attach unless you specify otherwise. Every container on a network receives a
10-
DNS name reachable from the host and from other containers on the same network. The
11-
domain suffix comes from the `[dns] domain` setting in `~/.config/container/config.toml`
12-
(see [`config.toml` reference](./container-system-config.md#dns)) — for example, with
13-
`domain = "test"` set, a container named `my-web-server` is reachable at
14-
`my-web-server.test`.
7+
containers attach unless you specify otherwise. Every container gets an IP address on
8+
its network, always reachable by that IP from the host and from other containers on the
9+
same network (find it with `container inspect <name>`).
10+
11+
## Set up DNS-based container names
12+
13+
Reaching a container by name instead of IP goes through `container`'s embedded DNS
14+
service. Set this up in two steps:
15+
16+
### Step 1: Tell the `container` service what domain to use
17+
18+
Edit `~/.config/container/config.toml`:
19+
20+
```toml
21+
[dns]
22+
domain = "test"
23+
```
24+
25+
Restart the service so it picks up the change:
26+
27+
```bash
28+
container system stop
29+
container system start
30+
```
31+
32+
From this point on, every container you run gets registered under `<name>.test` inside
33+
`container`'s DNS service, and every container's own DNS resolver is configured to look
34+
up `.test` names there too.
35+
36+
### Step 2: Tell macOS to use that domain too
37+
38+
Step 1 only affects the `container` service and the containers it runs — your Mac's own
39+
DNS resolver still knows nothing about `test`. Point it at `container`'s DNS service:
40+
41+
```bash
42+
sudo container system dns create test
43+
```
44+
45+
Enter your administrator password when prompted. This writes a resolver file to
46+
`/etc/resolver/` that tells macOS: for any `*.test` query, ask `127.0.0.1` instead of
47+
your normal DNS server.
48+
49+
Both steps are needed. See [`[dns]` reference](./container-system-config.md#dns) for the
50+
config-key-level detail.
51+
52+
With both steps done, confirm it end-to-end from your Mac:
53+
54+
```console
55+
% container run -d --rm --name my-web-server python:alpine python3 -m http.server 8000
56+
% curl http://my-web-server.test:8000
57+
```
1558

1659
## Container-to-container networking
1760

18-
From one container, use another container's DNS name to reach a service it exposes:
61+
From one container, use another container's DNS name to reach a service it exposes.
62+
This requires the DNS setup above ([Set up DNS-based container
63+
names](#set-up-dns-based-container-names)):
1964

2065
```bash
2166
container run --rm -d --name http-server python:alpine python3 -m http.server
2267
container run -it --rm alpine/curl curl -v http://http-server.test:8000
2368
container stop http-server
2469
```
2570

71+
> [!WARNING]
72+
> This works for containers on the `default` network using a domain-qualified name
73+
> (`http-server.test`, as above). It does **not** currently work for looking up another
74+
> container by its *bare* hostname (no domain suffix) on a custom network created with
75+
> `container network create` — the kind of zero-configuration, Compose-style service
76+
> discovery some users expect. That gap is tracked upstream as
77+
> [apple/container#1809](https://github.com/apple/container/issues/1809) (open feature
78+
> request, not yet implemented) and related broader reports in
79+
> [apple/container#856](https://github.com/apple/container/issues/856). Until resolved,
80+
> reach a container on a custom network by its IP address instead (`container inspect
81+
> <name>` to find it).
82+
2683
## Forward traffic from `localhost` to your container
2784

2885
Use the `--publish` option to forward TCP or UDP traffic from your loopback IP to the container you run. The option value has the form `[host-ip:]host-port:container-port[/protocol]`, where protocol may be `tcp` or `udp`, case insensitive.
@@ -153,9 +210,9 @@ Run `container network list` to see the networks that exist:
153210

154211
```console
155212
% container network list
156-
NETWORK STATE SUBNET
157-
default running 192.168.64.0/24
158-
foo running 192.168.65.0/24
213+
NETWORK SUBNET
214+
default 192.168.64.0/24
215+
foo 192.168.65.0/24
159216
%
160217
```
161218

docs/tutorials/container-system-config-tutorial.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ touch ~/.config/container/config.toml
3333

3434
Open the file in the editor of your choice and add only the sections and keys you want to change.
3535

36-
For this tutorial, increase the default CPU and memory limits used for each new container and set a DNS domain for resolving container IP addresses from the host.
36+
For this tutorial, increase the default CPU and memory limits used for each new container, and set a DNS domain so containers get hostnames under that domain (a container named `my-web-server` becomes `my-web-server.test`).
3737

3838
```toml
3939
[container]
@@ -55,6 +55,19 @@ container system stop
5555
container system start
5656
```
5757

58+
### Route macOS DNS queries for the domain to `container`
59+
60+
The `[dns] domain` change above only affects the `container` service and the containers
61+
it runs. Complete the setup by telling macOS to route `*.test` queries there too:
62+
63+
```bash
64+
sudo container system dns create test
65+
```
66+
67+
Enter your administrator password when prompted. See [Networking: Set up DNS-based
68+
container names](../networking.md#set-up-dns-based-container-names) for what this step
69+
does.
70+
5871
### Verify the values are loaded
5972

6073
Use `container system property list` (alias `ls`) to print the merged configuration that the `container` service is using.

docs/tutorials/start-here.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,16 @@ Use the `--help` flag to see which abbreviations exist.
105105

106106
### Set up a local DNS domain (optional)
107107

108-
`container` includes an embedded DNS service that simplifies access to your containerized applications. If you want to configure a local DNS domain named `test` for this tutorial, run:
108+
`container` includes an embedded DNS service that simplifies access to your containerized applications. For what each step does, see [Networking: Set up DNS-based container names](../networking.md#set-up-dns-based-container-names); the short version, to set up a domain named `test`:
109+
110+
Set `domain = "test"` under `[dns]` in `~/.config/container/config.toml`, then restart the service:
111+
112+
```bash
113+
container system stop
114+
container system start
115+
```
116+
117+
Then tell macOS to route `*.test` queries to `container`'s DNS service:
109118

110119
```bash
111120
sudo container system dns create test

0 commit comments

Comments
 (0)