Using an SDN

Using a software defined network

DC/OS provides each container with its own IP address by allowing you to run containers on a wide variety of IP-based virtual networks. In order to run containers on a virtual network, you must install a CNI or CNM network out-of-band. DC/OS itself comes with its own virtual networking solution called DC/OS Overlay, which the you can use to provide containers with unique IP addresses.

Using Virtual Networks

First, you must configure the virtual networks. Virtual networks are configured at install time. You must specify a canonical name for each network in the config.yaml. When your service needs to launch a container, refer to it by that canonical name. To use a virtual network in a Marathon app definition, specify the "network": "USER" property along with an ipAddress field in the form: {"ipAddress": {"network": "$MYNETWORK"}}. The value of $MYNETWORK is the canonical name of the network.

Example

The following Marathon application definition specifies a network named dcos-1, which refers to the target DC/OS virtual network of the same name.

  1. {
  2. "id":"my-networking",
  3. "cmd":"env; ip -o addr; sleep 30",
  4. "cpus":0.10,
  5. "mem":64,
  6. "instances":1,
  7. "backoffFactor":1.14472988585,
  8. "backoffSeconds":5,
  9. "ipAddress":{
  10. "networkName":"dcos-1"
  11. },
  12. "container":{
  13. "type":"DOCKER",
  14. "docker":{
  15. "network":"USER",
  16. "image":"busybox",
  17. "portMappings":[
  18. {
  19. "containerPort":123,
  20. "servicePort":80,
  21. "name":"foo"
  22. }
  23. ]
  24. }
  25. }
  26. }

Learn more about ports and networking in Marathon.