Skip to content

Link a workload to one port of another workload

POST
/api/docker/container-links
curl --request POST \
--url https://opfield.example.com/api/docker/container-links \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "sourceNodeId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "sourceType": "container", "sourceResourceId": "example", "targetNodeId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "targetType": "container", "targetResourceId": "example", "targetPort": 1, "alias": "example", "environment": { "host": "example", "port": "example", "url": "example" } }'

The consumer reaches the target as alias:targetPort on its own internal link network; the target needs no published port and no route, and cannot reach the consumer. Without environment names a container or deployment joins the link without a restart (a Compose service gets a new revision); with them the consumer is recreated once. Both Docker nodes need a daemon with secure_link_egress_v1. Needs docker:containers:edit on the consumer (docker:compose:manage for a Compose service), docker:containers:environment when environment names are set, and docker:containers:link on the target (docker:compose:manage for a Compose service).

JSON request body

Media typeapplication/json
object
sourceNodeId
required
string format: uuid
sourceType
required
string
Allowed values: container deployment compose_service
sourceResourceId
required
string
>= 1 characters <= 255 characters
targetNodeId
required
string format: uuid
targetType
required
string
Allowed values: container deployment compose_service
targetResourceId
required
string
>= 1 characters <= 255 characters
targetPort
required
integer
>= 1 <= 65535
alias
string
<= 63 characters /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/
environment
object
host
string
<= 128 characters /^[A-Za-z_][A-Za-z0-9_]*$/
port
string
<= 128 characters /^[A-Za-z_][A-Za-z0-9_]*$/
url
string
<= 128 characters /^[A-Za-z_][A-Za-z0-9_]*$/

Created

Media typeapplication/json
object
data
required

Resource object. Exact fields depend on the endpoint.

object
id
string
name
string
key
additional properties
Example
{
"data": {
"id": "nginx-prod",
"name": "nginx-prod",
"image": "nginx:1.27",
"state": "running",
"ports": [
"80/tcp"
]
}
}

Bad request

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"details": [
{
"path": [
"name"
],
"message": "Required"
}
]
}

Authentication required

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "UNAUTHORIZED",
"message": "Authentication required"
}

Forbidden

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "FORBIDDEN",
"message": "Insufficient permissions"
}

Not found

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "NOT_FOUND",
"message": "Resource not found"
}

Conflict

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "CONFLICT",
"message": "Resource already exists"
}

Unprocessable entity

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "UNPROCESSABLE_ENTITY",
"message": "Request could not be processed"
}

Internal server error

Media typeapplication/json
object
code
required

Error code

string
message
required

Human-readable error message

string
details

Additional error details

Example
{
"code": "INTERNAL_ERROR",
"message": "Internal server error"
}