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.

Typical use cases 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 and load balancing.
  • Managing service lifecycle as part of CI/CD pipelines or infrastructure automation.

For example, you can create a new service named "webapp" using the "nginx:latest" image, set environment variables for configuration, and specify 3 replicas to ensure redundancy.

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 A collection of environment variables to set inside the service's containers. Each variable has a name and value.
Replicas The number of service replicas to run (default is 1).

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, version, specifications, and status.

No binary data output is involved in this operation.

Dependencies

  • Requires an active Portainer instance accessible via its API.
  • Requires an API key credential configured in n8n to authenticate requests to the Portainer API.
  • The node uses the base URL and API key from the configured credentials to send HTTP requests.

Troubleshooting

  • Authentication errors: Ensure the API key credential is valid and has sufficient permissions to create services on the target Portainer environment.
  • Invalid environment ID: Verify that the provided environment ID corresponds to an existing endpoint in Portainer.
  • Image not found: The specified Docker image must be available in the registry accessible by the Docker Swarm nodes.
  • Incorrect environment variables format: Environment variables should be provided as name-value pairs; missing names or values may cause request failures.
  • Replica count issues: The replicas property must be a positive integer; zero or negative values are invalid.
  • API connectivity problems: Confirm network connectivity to the Portainer API endpoint and that the base URL is correctly configured.

Error messages returned by the Portainer API usually indicate the cause, such as unauthorized access, resource not found, or validation errors. Reviewing these messages helps identify and fix input or configuration issues.

Links and References

Discussion