DEV Community

Alex Spinov
Alex Spinov

Posted on

Portainer Has a Free API — Heres How to Manage Docker Without the Command Line

Portainer is a container management UI — manage Docker, Swarm, and Kubernetes through a web dashboard. Deploy, monitor, and troubleshoot containers without memorizing CLI commands.

Why Portainer?

  • Visual management: Web UI for all container operations
  • Multi-environment: Manage Docker, Swarm, K8s from one place
  • App templates: One-click deployments
  • RBAC: Team-based access control
  • REST API: Automate everything
  • Free CE: Community Edition is free forever

Install

docker volume create portainer_data
docker run -d -p 9443:9443 -p 8000:8000 \
  --name portainer --restart=always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer-ce:latest
Enter fullscreen mode Exit fullscreen mode

Dashboard at https://localhost:9443

API: Authenticate

curl -X POST https://localhost:9443/api/auth \
  -H 'Content-Type: application/json' \
  -d '{"username": "admin", "password": "your-password"}'
# Returns: {"jwt": "eyJhbG..."}
Enter fullscreen mode Exit fullscreen mode

API: List Containers

curl https://localhost:9443/api/endpoints/1/docker/containers/json \
  -H 'Authorization: Bearer JWT_TOKEN'
Enter fullscreen mode Exit fullscreen mode

API: Create Container

curl -X POST https://localhost:9443/api/endpoints/1/docker/containers/create?name=my-app \
  -H 'Authorization: Bearer JWT_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "Image": "nginx:latest",
    "ExposedPorts": {"80/tcp": {}},
    "HostConfig": {
      "PortBindings": {"80/tcp": [{"HostPort": "8080"}]}
    }
  }'
Enter fullscreen mode Exit fullscreen mode

API: Deploy Stack (Docker Compose)

curl -X POST https://localhost:9443/api/stacks/create/standalone/string \
  -H 'Authorization: Bearer JWT_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "my-stack",
    "stackFileContent": "services:\n  web:\n    image: nginx\n    ports:\n      - 8080:80",
    "env": [{"name": "ENV", "value": "production"}]
  }'
Enter fullscreen mode Exit fullscreen mode

API: Container Logs

curl https://localhost:9443/api/endpoints/1/docker/containers/CONTAINER_ID/logs?stdout=true&tail=100 \
  -H 'Authorization: Bearer JWT_TOKEN'
Enter fullscreen mode Exit fullscreen mode

API: Container Stats

curl https://localhost:9443/api/endpoints/1/docker/containers/CONTAINER_ID/stats?stream=false \
  -H 'Authorization: Bearer JWT_TOKEN'
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

A small ops team managed 40 containers across 5 servers with SSH and CLI. After Portainer, junior devs deploy and monitor containers through the UI. On-call incidents resolved 3x faster because logs, stats, and restart buttons are one click away.


Need to automate data collection? Check out my Apify actors for ready-made scrapers, or email spinov001@gmail.com for custom solutions.

Top comments (0)