Add a default value for the docker.network configuration
This commit is contained in:
parent
01f2b3cd20
commit
81f23cc732
4 changed files with 116 additions and 3 deletions
|
@ -71,6 +71,13 @@ usebindportip = true
|
||||||
#
|
#
|
||||||
swarmMode = false
|
swarmMode = false
|
||||||
|
|
||||||
|
# Define a default docker network to use for connections to all containers.
|
||||||
|
# Can be overridden by the traefik.docker.network label.
|
||||||
|
#
|
||||||
|
# Optional
|
||||||
|
#
|
||||||
|
network = "web"
|
||||||
|
|
||||||
# Enable docker TLS connection.
|
# Enable docker TLS connection.
|
||||||
#
|
#
|
||||||
# Optional
|
# Optional
|
||||||
|
@ -125,6 +132,13 @@ watch = true
|
||||||
#
|
#
|
||||||
swarmMode = true
|
swarmMode = true
|
||||||
|
|
||||||
|
# Define a default docker network to use for connections to all containers.
|
||||||
|
# Can be overridden by the traefik.docker.network label.
|
||||||
|
#
|
||||||
|
# Optional
|
||||||
|
#
|
||||||
|
network = "web"
|
||||||
|
|
||||||
# Override default configuration template.
|
# Override default configuration template.
|
||||||
# For advanced users :)
|
# For advanced users :)
|
||||||
#
|
#
|
||||||
|
@ -195,7 +209,7 @@ Labels can be used on containers to override default behavior.
|
||||||
|
|
||||||
| Label | Description |
|
| Label | Description |
|
||||||
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `traefik.docker.network` | Set the docker network to use for connections to this container. [1] |
|
| `traefik.docker.network` | Override the default docker network to use for connections to this container. [1] |
|
||||||
| `traefik.domain` | Default domain used for frontend rules. |
|
| `traefik.domain` | Default domain used for frontend rules. |
|
||||||
| `traefik.enable=false` | Disable this container in Træfik |
|
| `traefik.enable=false` | Disable this container in Træfik |
|
||||||
| `traefik.port=80` | Register this port. Useful when the container exposes multiples ports. |
|
| `traefik.port=80` | Register this port. Useful when the container exposes multiples ports. |
|
||||||
|
|
|
@ -196,7 +196,7 @@ func (p *Provider) getFrontendRule(container dockerData, segmentLabels map[strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Provider) getIPAddress(container dockerData) string {
|
func (p Provider) getIPAddress(container dockerData) string {
|
||||||
if value := label.GetStringValue(container.Labels, labelDockerNetwork, ""); value != "" {
|
if value := label.GetStringValue(container.Labels, labelDockerNetwork, p.Network); value != "" {
|
||||||
networkSettings := container.NetworkSettings
|
networkSettings := container.NetworkSettings
|
||||||
if networkSettings.Networks != nil {
|
if networkSettings.Networks != nil {
|
||||||
network := networkSettings.Networks[value]
|
network := networkSettings.Networks[value]
|
||||||
|
|
|
@ -63,6 +63,83 @@ func TestDockerBuildConfiguration(t *testing.T) {
|
||||||
CircuitBreaker: nil,
|
CircuitBreaker: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
desc: "when basic container configuration with multiple network",
|
||||||
|
containers: []docker.ContainerJSON{
|
||||||
|
containerJSON(
|
||||||
|
name("test"),
|
||||||
|
ports(nat.PortMap{
|
||||||
|
"80/tcp": {},
|
||||||
|
}),
|
||||||
|
withNetwork("bridge", ipv4("127.0.0.1")),
|
||||||
|
withNetwork("webnet", ipv4("127.0.0.2")),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
expectedFrontends: map[string]*types.Frontend{
|
||||||
|
"frontend-Host-test-docker-localhost-0": {
|
||||||
|
Backend: "backend-test",
|
||||||
|
PassHostHeader: true,
|
||||||
|
EntryPoints: []string{},
|
||||||
|
BasicAuth: []string{},
|
||||||
|
Routes: map[string]types.Route{
|
||||||
|
"route-frontend-Host-test-docker-localhost-0": {
|
||||||
|
Rule: "Host:test.docker.localhost",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedBackends: map[string]*types.Backend{
|
||||||
|
"backend-test": {
|
||||||
|
Servers: map[string]types.Server{
|
||||||
|
"server-test": {
|
||||||
|
URL: "http://127.0.0.2:80",
|
||||||
|
Weight: label.DefaultWeight,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CircuitBreaker: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "when basic container configuration with specific network",
|
||||||
|
containers: []docker.ContainerJSON{
|
||||||
|
containerJSON(
|
||||||
|
name("test"),
|
||||||
|
labels(map[string]string{
|
||||||
|
"traefik.docker.network": "mywebnet",
|
||||||
|
}),
|
||||||
|
ports(nat.PortMap{
|
||||||
|
"80/tcp": {},
|
||||||
|
}),
|
||||||
|
withNetwork("bridge", ipv4("127.0.0.1")),
|
||||||
|
withNetwork("webnet", ipv4("127.0.0.2")),
|
||||||
|
withNetwork("mywebnet", ipv4("127.0.0.3")),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
expectedFrontends: map[string]*types.Frontend{
|
||||||
|
"frontend-Host-test-docker-localhost-0": {
|
||||||
|
Backend: "backend-test",
|
||||||
|
PassHostHeader: true,
|
||||||
|
EntryPoints: []string{},
|
||||||
|
BasicAuth: []string{},
|
||||||
|
Routes: map[string]types.Route{
|
||||||
|
"route-frontend-Host-test-docker-localhost-0": {
|
||||||
|
Rule: "Host:test.docker.localhost",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedBackends: map[string]*types.Backend{
|
||||||
|
"backend-test": {
|
||||||
|
Servers: map[string]types.Server{
|
||||||
|
"server-test": {
|
||||||
|
URL: "http://127.0.0.3:80",
|
||||||
|
Weight: label.DefaultWeight,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
CircuitBreaker: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "when container has label 'enable' to false",
|
desc: "when container has label 'enable' to false",
|
||||||
|
@ -420,6 +497,7 @@ func TestDockerBuildConfiguration(t *testing.T) {
|
||||||
provider := &Provider{
|
provider := &Provider{
|
||||||
Domain: "docker.localhost",
|
Domain: "docker.localhost",
|
||||||
ExposedByDefault: true,
|
ExposedByDefault: true,
|
||||||
|
Network: "webnet",
|
||||||
}
|
}
|
||||||
actualConfig := provider.buildConfigurationV2(dockerDataList)
|
actualConfig := provider.buildConfigurationV2(dockerDataList)
|
||||||
require.NotNil(t, actualConfig, "actualConfig")
|
require.NotNil(t, actualConfig, "actualConfig")
|
||||||
|
@ -938,6 +1016,24 @@ func TestDockerGetIPAddress(t *testing.T) {
|
||||||
),
|
),
|
||||||
expected: "127.0.0.1",
|
expected: "127.0.0.1",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
container: containerJSON(
|
||||||
|
networkMode("host"),
|
||||||
|
withNetwork("testnet", ipv4("10.11.12.13")),
|
||||||
|
withNetwork("webnet", ipv4("10.11.12.14")),
|
||||||
|
),
|
||||||
|
expected: "10.11.12.14",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
container: containerJSON(
|
||||||
|
labels(map[string]string{
|
||||||
|
labelDockerNetwork: "testnet",
|
||||||
|
}),
|
||||||
|
withNetwork("testnet", ipv4("10.11.12.13")),
|
||||||
|
withNetwork("webnet", ipv4("10.11.12.14")),
|
||||||
|
),
|
||||||
|
expected: "10.11.12.13",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
container: containerJSON(
|
container: containerJSON(
|
||||||
networkMode("host"),
|
networkMode("host"),
|
||||||
|
@ -962,7 +1058,9 @@ func TestDockerGetIPAddress(t *testing.T) {
|
||||||
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
segmentProperties := label.ExtractTraefikLabels(dData.Labels)
|
||||||
dData.SegmentLabels = segmentProperties[""]
|
dData.SegmentLabels = segmentProperties[""]
|
||||||
|
|
||||||
provider := &Provider{}
|
provider := &Provider{
|
||||||
|
Network: "webnet",
|
||||||
|
}
|
||||||
|
|
||||||
actual := provider.getIPAddress(dData)
|
actual := provider.getIPAddress(dData)
|
||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
|
|
|
@ -45,6 +45,7 @@ type Provider struct {
|
||||||
ExposedByDefault bool `description:"Expose containers by default" export:"true"`
|
ExposedByDefault bool `description:"Expose containers by default" export:"true"`
|
||||||
UseBindPortIP bool `description:"Use the ip address from the bound port, rather than from the inner network" export:"true"`
|
UseBindPortIP bool `description:"Use the ip address from the bound port, rather than from the inner network" export:"true"`
|
||||||
SwarmMode bool `description:"Use Docker on Swarm Mode" export:"true"`
|
SwarmMode bool `description:"Use Docker on Swarm Mode" export:"true"`
|
||||||
|
Network string `description:"Default Docker network used" export:"true"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// dockerData holds the need data to the Provider p
|
// dockerData holds the need data to the Provider p
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue