Create a network Run in API Explorer

POST /networks/create
application/json

Body Required

Network configuration

  • Name string Required

    The network's name.

  • Driver string

    Name of the network driver plugin to use.

    Default value is bridge.

  • Scope string

    The level at which the network exists (e.g. swarm for cluster-wide or local for machine level).

  • Internal boolean

    Restrict external access to the network.

  • Attachable boolean

    Globally scoped network is manually attachable by regular containers from workers in swarm mode.

  • Ingress boolean

    Ingress network is the network which provides the routing-mesh in swarm mode.

  • ConfigOnly boolean

    Creates a config-only network. Config-only networks are placeholder networks for network configurations to be used by other networks. Config-only networks cannot be used directly to run containers or services.

    Default value is false.

  • ConfigFrom object

    The config-only network source to provide the configuration for this network.

    Hide ConfigFrom attribute Show ConfigFrom attribute object
    • Network string

      The name of the config-only network that provides the network's configuration. The specified network must be an existing config-only network. Only network names are allowed, not network IDs.

  • IPAM object
    Hide IPAM attributes Show IPAM attributes object
    • Driver string

      Name of the IPAM driver to use.

      Default value is default.

    • Config array[object]

      List of IPAM configuration options, specified as a map:

      {"Subnet": <CIDR>, "IPRange": <CIDR>, "Gateway": <IP address>, "AuxAddress": <device_name:IP address>}
      
      Hide Config attributes Show Config attributes object
      • Subnet string
      • IPRange string
      • Gateway string
      • AuxiliaryAddresses object
        Hide AuxiliaryAddresses attribute Show AuxiliaryAddresses attribute object
        • * string Additional properties
    • Options object

      Driver-specific options, specified as a map.

      Hide Options attribute Show Options attribute object
      • * string Additional properties
  • EnableIPv4 boolean

    Enable IPv4 on the network.

  • EnableIPv6 boolean

    Enable IPv6 on the network.

  • Options object

    Network specific options to be used by the drivers.

    Hide Options attribute Show Options attribute object
    • * string Additional properties
  • Labels object

    User-defined key/value metadata.

    Hide Labels attribute Show Labels attribute object
    • * string Additional properties

Responses

  • 201 application/json

    Network created successfully

    Hide response attributes Show response attributes object
    • Id string Required

      The ID of the created network.

    • Warning string Required

      Warnings encountered when creating the container

  • 400 application/json

    bad parameter

    Hide response attribute Show response attribute object
    • message string Required

      The error message.

  • 403 application/json

    Forbidden operation. This happens when trying to create a network named after a pre-defined network, or when trying to create an overlay network on a daemon which is not part of a Swarm cluster.

    Hide response attribute Show response attribute object
    • message string Required

      The error message.

  • 404 application/json

    plugin not found

    Hide response attribute Show response attribute object
    • message string Required

      The error message.

  • 500 application/json

    Server error

    Hide response attribute Show response attribute object
    • message string Required

      The error message.

POST /networks/create
curl \
 --request POST 'http://api.example.com/v1.49/networks/create' \
 --header "Content-Type: application/json" \
 --data '{"Name":"my_network","Driver":"bridge","Scope":"string","Internal":true,"Attachable":true,"Ingress":false,"ConfigOnly":false,"ConfigFrom":{"Network":"config_only_network_01"},"IPAM":{"Driver":"default","Config":[{"Subnet":"172.20.0.0/16","IPRange":"172.20.10.0/24","Gateway":"172.20.10.11","AuxiliaryAddresses":{"additionalProperty1":"string","additionalProperty2":"string"}}],"Options":{"foo":"bar"}},"EnableIPv4":true,"EnableIPv6":true,"Options":{"com.docker.network.driver.mtu":"1500","com.docker.network.bridge.name":"docker0","com.docker.network.bridge.enable_icc":"true","com.docker.network.bridge.default_bridge":"true","com.docker.network.bridge.host_binding_ipv4":"0.0.0.0","com.docker.network.bridge.enable_ip_masquerade":"true"},"Labels":{"com.example.some-label":"some-value","com.example.some-other-label":"some-other-value"}}'
Request examples
{
  "Name": "my_network",
  "Driver": "bridge",
  "Scope": "string",
  "Internal": true,
  "Attachable": true,
  "Ingress": false,
  "ConfigOnly": false,
  "ConfigFrom": {
    "Network": "config_only_network_01"
  },
  "IPAM": {
    "Driver": "default",
    "Config": [
      {
        "Subnet": "172.20.0.0/16",
        "IPRange": "172.20.10.0/24",
        "Gateway": "172.20.10.11",
        "AuxiliaryAddresses": {
          "additionalProperty1": "string",
          "additionalProperty2": "string"
        }
      }
    ],
    "Options": {
      "foo": "bar"
    }
  },
  "EnableIPv4": true,
  "EnableIPv6": true,
  "Options": {
    "com.docker.network.driver.mtu": "1500",
    "com.docker.network.bridge.name": "docker0",
    "com.docker.network.bridge.enable_icc": "true",
    "com.docker.network.bridge.default_bridge": "true",
    "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
    "com.docker.network.bridge.enable_ip_masquerade": "true"
  },
  "Labels": {
    "com.example.some-label": "some-value",
    "com.example.some-other-label": "some-other-value"
  }
}
Response examples (201)
{
  "Id": "b5c4fc71e8022147cd25de22b22173de4e3b170134117172eb595cb91b4e7e5d",
  "Warning": "string"
}
Response examples (400)
{
  "message": "Something went wrong."
}
Response examples (400)
{
  "message": "Something went wrong."
}
Response examples (403)
{
  "message": "Something went wrong."
}
Response examples (403)
{
  "message": "Something went wrong."
}
Response examples (404)
{
  "message": "Something went wrong."
}
Response examples (404)
{
  "message": "Something went wrong."
}
Response examples (500)
{
  "message": "Something went wrong."
}
Response examples (500)
{
  "message": "Something went wrong."
}