Portainer icon

Portainer

Trabalhe com dados da API do Portainer para gerenciar Docker

Overview

This node integrates with the Portainer API to manage Docker Swarm services programmatically. Specifically, the Service - Create operation allows users to create a new Docker Swarm service within a specified environment (endpoint). This is useful for automating deployment and scaling of containerized applications managed by Docker Swarm through Portainer.

Common scenarios include:

  • Automating the deployment of microservices in a Docker Swarm cluster.
  • Creating services with specific Docker images and environment variables.
  • Defining the number of replicas for high availability or load balancing.

Practical example:

  • Deploying an Nginx web server as a Docker Swarm service named "webserver" using the image nginx:latest with 3 replicas and custom environment variables.

Properties

Name Meaning
Environment ID The ID of the Portainer environment/endpoint where the service will be created.
Service Name The name to assign to the new Docker Swarm service.
Image The Docker image to use for the service's containers (e.g., nginx:latest).
Environment Variables List of environment variables to set inside the service containers. Each variable has a Name and Value.
Replicas Number of service replicas to run (scale factor).

Output

The node outputs JSON data representing the response from the Portainer API after creating the service. This typically includes details about the newly created service such as its ID, configuration, and status.

No binary data output is involved in this operation.

Dependencies

  • Requires a configured Portainer API credential with:

    • Base URL of the Portainer instance.
    • An API key for authentication.
  • The node sends HTTP POST requests to the Portainer API endpoint /endpoints/{environmentId}/docker/services/create.

Troubleshooting

  • Common issues:

    • Invalid or missing Environment ID: Ensure the environment ID corresponds to a valid Portainer endpoint.
    • Incorrect or unavailable Docker image: Verify the image name and tag exist and are accessible.
    • Insufficient permissions: The API key must have rights to create services on the target environment.
    • Network connectivity problems between n8n and Portainer API.
  • Error messages:

    • Authentication errors: Check API key validity and permissions.
    • Validation errors from Portainer API: Confirm all required fields (service name, image) are provided and correctly formatted.
    • HTTP errors (4xx or 5xx): Inspect the error message returned by the API for clues; may require checking Portainer logs or network settings.

Links and References


If you need further details on other operations or resources, feel free to ask!

Discussion