Connect a container to a network Run in API Explorer

POST /networks/{id}/connect

The network must be either a local-scoped network or a swarm-scoped network with the attachable option set. A network cannot be re-attached to a running container

Path parameters

  • id string Required

    Network ID or name

application/json

Body Required

  • Container string

    The ID or name of the container to connect to the network.

  • EndpointConfig object

    Configuration for a network endpoint.

    Hide EndpointConfig attributes Show EndpointConfig attributes object
    • IPAMConfig object

      EndpointIPAMConfig represents an endpoint's IPAM configuration.

      Hide IPAMConfig attributes Show IPAMConfig attributes object
      • IPv4Address string
      • IPv6Address string
      • LinkLocalIPs array[string]
    • MacAddress string

      MAC address for the endpoint on this network. The network driver might ignore this parameter.

    • Aliases array[string]
    • NetworkID string

      Unique ID of the network.

    • EndpointID string

      Unique ID for the service endpoint in a Sandbox.

    • Gateway string

      Gateway address for this network.

    • IPAddress string

      IPv4 address.

    • IPPrefixLen integer

      Mask length of the IPv4 address.

    • IPv6Gateway string

      IPv6 gateway address.

    • GlobalIPv6Address string

      Global IPv6 address.

    • GlobalIPv6PrefixLen integer(int64)

      Mask length of the global IPv6 address.

    • DriverOpts object

      DriverOpts is a mapping of driver options and values. These options are passed directly to the driver and are driver specific.

      Hide DriverOpts attribute Show DriverOpts attribute object
      • * string Additional properties
    • DNSNames array[string]

      List of all DNS names an endpoint has on a specific network. This list is based on the container name, network aliases, container short ID, and hostname.

      These DNS names are non-fully qualified but can contain several dots. You can get fully qualified DNS names by appending .<network-name>. For instance, if container name is my.ctr and the network is named testnet, DNSNames will contain my.ctr and the FQDN will be my.ctr.testnet.

Responses

  • 200

    No error

  • 400 application/json

    bad parameter

    Hide response attribute Show response attribute object
    • message string Required

      The error message.

  • 403 application/json

    Operation forbidden

    Hide response attribute Show response attribute object
    • message string Required

      The error message.

  • 404 application/json

    Network or container 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/{id}/connect
curl \
 --request POST 'http://api.example.com/v1.44/networks/{id}/connect' \
 --header "Content-Type: application/json" \
 --data '{"Container":"3613f73ba0e4","EndpointConfig":{"IPAMConfig":{"IPv4Address":"172.24.56.89","IPv6Address":"2001:db8::5689"},"MacAddress":"02:42:ac:12:05:02"}}'
Request examples
{
  "Container": "3613f73ba0e4",
  "EndpointConfig": {
    "IPAMConfig": {
      "IPv4Address": "172.24.56.89",
      "IPv6Address": "2001:db8::5689"
    },
    "MacAddress": "02:42:ac:12:05:02"
  }
}
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."
}