Link a workload to one port of another workload
const url = 'https://opfield.example.com/api/docker/container-links';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"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"}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}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).
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”JSON request body
object
object
Responses
Section titled “Responses”Created
object
Resource object. Exact fields depend on the endpoint.
object
Example
{ "data": { "id": "nginx-prod", "name": "nginx-prod", "image": "nginx:1.27", "state": "running", "ports": [ "80/tcp" ] }}Bad request
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "VALIDATION_ERROR", "message": "Request validation failed", "details": [ { "path": [ "name" ], "message": "Required" } ]}Authentication required
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "UNAUTHORIZED", "message": "Authentication required"}Forbidden
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "FORBIDDEN", "message": "Insufficient permissions"}Not found
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "NOT_FOUND", "message": "Resource not found"}Conflict
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "CONFLICT", "message": "Resource already exists"}Unprocessable entity
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "UNPROCESSABLE_ENTITY", "message": "Request could not be processed"}Internal server error
object
Error code
Human-readable error message
Additional error details
Example
{ "code": "INTERNAL_ERROR", "message": "Internal server error"}