With Portainer we can monitor multiple Docker Swarms from one Portainer Server. To connect an existing Portainer server to an agent
Configure the Agent
- For security reasons, by default, the Portainer Agent only accepts connection from the first Portainer Server it encounters. To enable the Portainer Agent to connect to multiple Portainer Servers, add the AGENT_SECRET environment variable to the docker-compose.yml file of the Agent. This is necessary if you launch a Portainer Server on the Docker host and connect to the local Agent to test it. Without specifying the AGENT_SECRET, another Portainer Server cannot connect to the same agent.
- Publish the Agent port on the host network
environment:
# REQUIRED: Should be equal to the service name prefixed by "tasks." when
# deployed inside an overlay network
AGENT_CLUSTER_ADDR: tasks.agent
# AGENT_PORT: 9001
# LOG_LEVEL: debug
AGENT_SECRET: my_secret_token
ports:
- target: 9001
published: 9001
protocol: tcp
mode: host
Configure the Server
- Add the AGENT_SECRET environment variable to the docker-compose.yml file of the Server
environment:
AGENT_SECRET: my_secret_token
Add the endpoint to the Portainer Server
- Log into the Portainer Server
- Navigate to the Endpoints page
- Click the Add Endpoint button
- Select the Agent endpoint type
- Enter the IP address and the port number ( by default 9001 ) of the Portainer Agent