Skip to content

Commit

Permalink
feat: support IPv6 network on the docker provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tomMoulard committed Sep 7, 2022
1 parent 703de53 commit 251e93e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/content/providers/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ On Linux, for versions of Docker older than 20.10.0, for `host.docker.internal`
as an `extra_host` to the Traefik container, using the `--add-host` flag. For example, to set it to the IP address of
the bridge interface (`docker0` by default): `--add-host=host.docker.internal:172.17.0.1`

### IPv4 && IPv6

When using a docker stack that uses IPv6,
Traefik will use the IPv4 container IP before its IPv6 counterpart.
Therefore, on an IPv6 docker stack,
Traefik will use the IPv6 container IP.

### Docker API Access

Traefik requires access to the docker socket to get its dynamic configuration.
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/docker/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func ipv4(ip string) func(*network.EndpointSettings) {
}
}

func ipv6(ip string) func(*network.EndpointSettings) {
return func(s *network.EndpointSettings) {
s.GlobalIPv6Address = ip
}
}

func swarmTask(id string, ops ...func(*swarm.Task)) swarm.Task {
task := &swarm.Task{
ID: id,
Expand Down
16 changes: 16 additions & 0 deletions pkg/provider/docker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3511,6 +3511,22 @@ func TestDockerGetIPAddress(t *testing.T) {
network: "testnet",
expected: "10.11.12.13",
},
{
desc: "one ipv6 network, network label",
container: containerJSON(
withNetwork("testnet", ipv6("fd00:1:2:3:4::")),
),
network: "testnet",
expected: "fd00:1:2:3:4::",
},
{
desc: "two network ipv4 + ipv6, network label",
container: containerJSON(
withNetwork("testnet", ipv4("10.11.12.13"), ipv6("fd00:1:2:3:4::")),
),
network: "testnet",
expected: "10.11.12.13",
},
{
desc: "two networks, network label",
container: containerJSON(
Expand Down
7 changes: 6 additions & 1 deletion pkg/provider/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,15 @@ func parseContainer(container dockertypes.ContainerJSON) dockerData {
if container.NetworkSettings.Networks != nil {
dData.NetworkSettings.Networks = make(map[string]*networkData)
for name, containerNetwork := range container.NetworkSettings.Networks {
addr := containerNetwork.IPAddress
if addr == "" {
addr = containerNetwork.GlobalIPv6Address
}

dData.NetworkSettings.Networks[name] = &networkData{
ID: containerNetwork.NetworkID,
Name: name,
Addr: containerNetwork.IPAddress,
Addr: addr,
}
}
}
Expand Down

0 comments on commit 251e93e

Please sign in to comment.