---
title: "Connect a container to a network"
method: POST
path: "/networks/{id}/connect"
tags: ["Network"]
---

# Connect a container to a network

`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

## Request body

- object
  - `Container` string — The ID or name of the container to connect to the network.
  - `EndpointConfig` EndpointSettings — Configuration for a network endpoint.
    - `IPAMConfig` EndpointIPAMConfig, nullable — EndpointIPAMConfig represents an endpoint's IPAM configuration.
      - `IPv4Address` string
      - `IPv6Address` string
      - `LinkLocalIPs` string[]
    - `Links` string[]
    - `MacAddress` string — MAC address for the endpoint on this network. The network driver might ignore this parameter.
    - `Aliases` string[]
    - `DriverOpts` object, nullable — DriverOpts is a mapping of driver options and values. These options are passed directly to the driver and are driver specific.
    - `GwPriority` number — This property determines which endpoint will provide the default gateway for a container. The endpoint with the highest priority will be used. If multiple endpoints have the same priority, endpoints are lexicographically sorted based on their network name, and the one that sorts first is picked.
    - `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 — Mask length of the global IPv6 address.
    - `DNSNames` 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`.

## Response `200`

No error

## Other responses

- `400` — bad parameter
- `403` — Operation forbidden
- `404` — Network or container not found
- `500` — Server error

---

[API](https://skmtc.net/chapar-rest/apis/docker-engine-api.md) · [All operations](https://skmtc.net/chapar-rest/apis/docker-engine-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/chapar-rest/docker-engine-api/versions/3a78a994dd0d/schema)
