Skip to content

Support for Container Network Mode #140

@engels74

Description

@engels74

Feature Request: Support for Container Network Mode

Problem Statement

Wings currently hardcodes the Hostname field when creating Docker containers, which prevents the use of network_mode: container:<name> in the Docker configuration. This limitation stems from a conflict between Docker's API requirements and Wings' container creation logic.

Current Behavior

When attempting to configure Wings with network_mode: container:<name> in config.yml:

docker:
  network:
    network_mode: container:caddy

Container creation fails with the following error:

ERROR: failed to create server environment during install process 
error=environment/docker: failed to create container: Error response from daemon: 
conflicting options: hostname and the network mode

Root Cause

The Docker API explicitly prohibits setting a custom hostname when using network_mode: container:<name> because containers sharing another container's network namespace must inherit that container's hostname. However, Wings unconditionally sets the hostname to the server UUID at line 181 in environment/docker/container.go:

conf := &container.Config{
    Hostname:     e.Id,  // Always set, regardless of network mode
    Domainname:   cfg.Docker.Domainname,
    // ...
}

This prevents game server containers from sharing another container's network namespace entirely.

Use Case

Scenario: VPN-Routed Game Servers

My deployment pattern involves routing game server traffic through a VPN connection to protect the host's IP address. This can be achieved by:

  1. Running a VPN container (e.g., Caddy with WireGuard) on a Docker bridge network
  2. Configuring game server containers to use network_mode: container:caddy to share the VPN container's network namespace
  3. All game server traffic is then routed through the VPN connection

Example Network Configuration:

  • Bridge network: caddy_backbone (172.20.0.0/24)
  • VPN container: caddy with WireGuard connection
  • Game servers: Should use network_mode: container:caddy to route through VPN

Current Workaround Limitations

The only current alternative is to use a standard bridge network (network_mode: caddy_backbone), but this does not route traffic through the VPN. Containers on the same bridge network are merely neighbors with independent internet connections.

Benefits

Supporting network_mode: container:<name> would enable:

  • VPN Integration: Route traffic through a VPN container for IP protection and DDoS mitigation without exposing the host’s IP.
  • Resource Efficiency: Reduces overhead by reusing an existing network stack instead of spawning additional network interfaces per container.
  • Advanced Topologies: Allows containers to share networking contexts for sidecar patterns, debugging, or dependency coupling (e.g., game server ↔ proxy).
  • Backward Compatibility: Default configurations remain unaffected. Only containers explicitly sharing a network namespace omit the hostname.

Proposed Solution

Add conditional logic to skip setting the hostname when using container network mode. The hostname should only be set when the container has its own network namespace.

Technical Details

Affected Files

  • environment/docker/container.go (line 181): Game server container creation

Configuration

The network mode is read from the Wings configuration:

networkMode := container.NetworkMode(cfg.Docker.Network.Mode)

This value comes from config.yml:

docker:
  network:
    network_mode: container:caddy  # or any other container name

Docker API Constraint

From Docker's perspective, when using network_mode: container:<name>:

  • The container shares the target container's network namespace entirely
  • This includes network interfaces, IP addresses, ports, and hostname
  • Setting a custom hostname creates an inconsistency and is therefore rejected

Compatibility

This change can be backward compatible:

  • Existing configurations using bridge networks or default network mode will continue to work
  • The hostname will still be set for all standard network configurations
  • Only containers explicitly using network_mode: container:<name> will have the hostname omitted

References

  • Docker API documentation on network modes
  • Wings configuration: config/config_docker.go (DockerNetworkConfiguration struct)
  • Container creation logic: environment/docker/container.go (Create function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions