Docker icon

Docker

Interact with Docker via Portainer API

Actions107

Overview

This node allows you to interact with Docker containers through the Portainer API, specifically enabling you to delete a container on a selected Docker endpoint. It is useful in automation workflows where you need to programmatically manage container lifecycles, such as cleaning up unused or stopped containers, or forcibly removing containers that are running.

Practical examples include:

  • Automatically deleting containers after a CI/CD pipeline finishes.
  • Cleaning up containers based on certain conditions or schedules.
  • Forcibly removing containers that are stuck or unresponsive.

Properties

Name Meaning
EndpointID Name or ID Select the Docker endpoint by name or ID to target for the container deletion.
Id The ID or name of the container to be deleted.
Additional Fields Optional parameters to customize the deletion behavior:
- V Remove anonymous volumes associated with the container (boolean).
- Force If the container is running, kill it before removing it (boolean).
- Link Remove the specified link associated with the container (boolean).

Output

The node outputs JSON data representing the response from the Portainer API after attempting to delete the container. This typically includes status information about the deletion operation. There is no binary output.

Dependencies

  • Requires an active connection to a Portainer API instance.
  • Needs an API key credential configured in n8n to authenticate requests to the Portainer API.
  • The user must specify a valid Docker endpoint within Portainer to target the container deletion.

Troubleshooting

  • Common issues:

    • Invalid or missing container ID/name will cause the deletion to fail.
    • Insufficient permissions or invalid API credentials can result in authentication errors.
    • Trying to delete a running container without setting "Force" to true may fail.
    • Network connectivity issues to the Portainer API endpoint.
  • Error messages and resolutions:

    • 404 Not Found: The specified container ID does not exist on the selected endpoint. Verify the container ID.
    • 401 Unauthorized: API credentials are invalid or missing. Check and update the API key credential.
    • 409 Conflict: Container is running and "Force" option is false. Enable "Force" to kill the container before removal.
    • 500 Internal Server Error: Server-side error at Portainer. Retry later or check Portainer server logs.

Links and References

Discussion