Terraform Docker Provider: "Bind" port to specific network

658 Views Asked by At

Launching a Docker Container that supports three networks: Default Bridge(OAM), Bridge(Data In), & MacVLAN(Data Out). The problem is that the Docker Provider seems to setup all the defined ports on the Default Bridge. How do I tell Terraform to bind the defined ports to a specific Docker Network??

The .tf file snippit:

ports {
  # Data-In (Bridge)
  internal = 881
  external = 881
}
ports {
  # SSH Access on Default Bridge
  internal = 22
  external = 222
}
networks_advanced {
  name = "bridge"
}
networks_advanced {
  name = "data-in-net"
}
networks_advanced {
  name = "data-out-net"
}

The Docker networks:

# docker network list
NETWORK ID          NAME                DRIVER              SCOPE
1c2441b0b530        bridge              bridge              local
c68892f0c6e5        host                host                local
bb45d9dcbad1        none                null                local
a318d3bf3075        data-out-net        macvlan             local
af806334c7bf        data-in-net         bridge              local

Port 222 works, port 881 does not.

IPTables from the host OS running Docker:

Chain DOCKER (2 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:9000
ACCEPT     tcp  --  anywhere             172.17.0.2           tcp dpt:8000
ACCEPT     tcp  --  anywhere             192.168.32.2         tcp dpt:601
ACCEPT     udp  --  anywhere             192.168.32.2         udp dpt:syslog
ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:881
ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:https
ACCEPT     tcp  --  anywhere             172.17.0.3           tcp dpt:ssh

The tcp dpt:881 line needs to have a destination of 192.168.32.3. The syslog container ONLY uses the Data-In Docker Network, and thus has a correct IP address.

Any sugggestions/workarounds?? Thanks! :)

0

There are 0 best solutions below