๐Ÿ”Œ Portainer Agent

Portainer Agent is a lightweight component that runs on Docker hosts to allow a central Portainer instance to manage them securely. It creates a secure tunnel between your main Portainer server and remote Docker environments without requiring direct Docker socket exposure over the network.

This allows you to manage multiple MOS Hub/Docker hosts from a single Portainer dashboard.

๐Ÿท๏ธ Category: Productivity

๐Ÿณ Image: portainer/agent:latest


ย  ย 
๐ŸŒ Website portainer.io
๐Ÿ“– Docs docs.portainer.io
๐Ÿ› Support GitHub Issues

๐ŸŒ Ports

Port Protocol Description
9001 TCP Portainer Agent communication port. The central Portainer instance connects to this port.

๐Ÿ’พ Volumes

Host Path Container Path Mode Description
/var/run/docker.sock /var/run/docker.sock RW Docker socket for container management
/var/lib/docker/volumes /var/lib/docker/volumes RW Docker volumes directory
/ /host RO Host root filesystem (for volume browsing)

โš™๏ธ Environment Variables

Variable Default Masked Description
AGENT_SECRET `` โœ… Optional shared secret for authentication. Must match in Portainer when adding environment.
PUID 500 โŒ User ID for file permissions
PGID 500 โŒ Group ID for file permissions
TZ Europe/Vienna โŒ Timezone for the container

๐Ÿš€ Quick Start

Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Portainer     โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚  Portainer      โ”‚
โ”‚   (Central)     โ”‚  :9001  โ”‚  Agent          โ”‚
โ”‚   Management    โ”‚         โ”‚  (This Host)    โ”‚
โ”‚   Interface     โ”‚         โ”‚                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                            โ”‚  Local Docker   โ”‚
                            โ”‚  Environment    โ”‚
                            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Step 1: Install Portainer Agent via MOS Hub

  1. Open the MOS Hub and search for Portainer-Agent
  2. Click Install
  3. The agent will start on port 9001
  4. Make note of this hostโ€™s IP address

Step 2: Get Host IP Address

Find the IP of this MOS Hub server:

ip addr show

Youโ€™ll need: http://HOST_IP:9001 for the next step.

Step 3: Add Environment in Central Portainer

On your main Portainer instance:

  1. Go to Environments โ†’ Add Environment
  2. Select Docker Standalone
  3. Select Agent as the connection method
  4. Enter details:
    • Name: MOS Hub Server (or any descriptive name)
    • Environment URL: http://HOST_IP:9001 (replace with actual IP)
    • Agent Secret: (if you set AGENT_SECRET, enter it here)
  5. Click Connect

Step 4: Verify Connection

  1. The environment should show as Up
  2. Click on the new environment to view its containers
  3. You can now manage this remote MOS Hub from your central Portainer!

๐Ÿ” Security Considerations

Network Security

  • Firewall: Only allow port 9001 access from your Portainer server IP
  • Internal Network: Keep the agent on internal/VPN network if possible
  • AGENT_SECRET: Always set a shared secret for production use

Privileged Access

โš ๏ธ Warning: The agent requires:

  • Access to Docker socket (full container control)
  • Access to host filesystem (for volume management)
  • Privileged mode enabled

Only deploy the agent on hosts you trust and control completely.


๐ŸŒ Use Cases

Centralized Management

Manage multiple MOS Hub servers from one dashboard:

  • Home server
  • VPS in cloud
  • Raspberry Pi at another location
  • Friendโ€™s server (with permission!)

Remote Monitoring

Check container status, logs, and resource usage on remote hosts without SSH.

Remote Deployment

Deploy containers to remote hosts from your central Portainer interface.


๐Ÿ”„ High Availability Setup

For production environments:

  1. Multiple Agents: Deploy agents on all Docker hosts
  2. Load Balancing: Use multiple Portainer replicas (BE feature)
  3. Backup: Backup Portainer data to restore connections

๐Ÿ“ Troubleshooting

Agent Not Connecting

  1. Check if agent is running:
    docker ps | grep portainer-agent
    
  2. Verify port is accessible:
    curl http://localhost:9001
    

    Should return agent info.

  3. Check firewall rules: Ensure port 9001 is open between Portainer and Agent.

  4. Check logs:
    docker logs portainer-agent
    

Connection Timeout

  • Verify IP address is correct
  • Check network connectivity: ping PORTAINER_IP from agent host
  • Ensure no NAT/firewall blocking port 9001

Authentication Failed

If using AGENT_SECRET:

  • Ensure secret matches exactly in Portainer and Agent
  • Restart agent after changing secret

โš ๏ธ Warning: The Portainer Agent has significant access to your Docker host. Only install it on hosts you control and trust. Never expose port 9001 to the public internet without firewall restrictions!

๐Ÿ’ก Tip: Use a VPN or private network for agent communication instead of exposing port 9001 publicly.

๐Ÿ’ก Tip: Set a strong AGENT_SECRET to prevent unauthorized connections even if port 9001 is somehow accessed.

๐Ÿ’ก Tip: You can manage the Agent container itself through MOS Hub - but if you stop it, youโ€™ll lose remote management until you restart it locally!

๐Ÿ“š For more information: Visit the Portainer Agent Documentation for advanced configuration and Edge Agent setup.


MOS Templates โ€“ maintained by J000K3R

This site uses Just the Docs, a documentation theme for Jekyll.