Using the Portainer Agent

Using the Portainer Agent

Rather than connecting Portainer to your Docker hosts via the Daemon over TCP, we recommend using the Portainer agent..

To deploy the agent, you have a few options depending on your Docker configuration... let me walk you through these now..

Option 1 - New Portainer Instance, Agent on same cluster as Portainer (Linux):

via Stack file

Using_the_Portainer_Agent-01

or via CLI

docker service create --name portainer --network portainer_agent_network --publish 9000:9000 --replicas=1 --mount src=portainer_data,dst=/data --constraint 'node.role == manager' portainer/portainer -H "tcp://tasks.portainer_agent:9001" --tlsskipverify

docker service create --name portainer_agent --network portainer_agent_network --publish mode=host,target=9001,published=9001 -e AGENT_CLUSTER_ADDR=tasks.portainer_agent --mode global --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock --mount type=bind,src=//var/lib/docker/volumes,dst=/var/lib/docker/volumes portainer/agent

Option 2 - Existing Portainer Instance, Agent on Remote Swarm Cluster (Linux)

via Stack file

Using_the_Portainer_Agent-02

or via CLI

docker service create --name portainer_agent --network portainer_agent_network --publish mode=host,target=9001,published=9001 -e AGENT_CLUSTER_ADDR=tasks.portainer_agent --mode global --mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock --mount type=bind,src=//var/lib/docker/volumes,dst=/var/lib/docker/volumes portainer/agent

Option 3 - Existing Portainer Instance, Agent on Remote Docker Host (Linux)

via Compose

Using_the_Portainer_Agent-03

or via CLI

docker run -d -p 9001:9001 --name portainer_agent --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker/volumes:/var/lib/docker.volumes portainer/agent

Option 4 - Existing Portainer Instance, Agent on Remote Windows Docker Host (Windows 2016 - 1803)

only available via CLI

docker run -d -p 9001:9001 --name portainer_agent --restart=always -v \\.\pipe\docker_engine:\\.\pipe\docker_engine portainer/agent

Option 5 - Existing Portainer Instance, Agent on Remote Windows Docker Host in Swarm Cluster (Windows 2016 - 1803)

only available via CLI

docker run -d -p 9001:9001 --name portainer_agent --restart=always -v \\.\pipe\docker_engine:\\.\pipe\docker_engine -e AGENT_CLUSTER_ADDR=tasks.agent portainer/agent


2 Comments

    • Thanks for the useful blog.
      Reading the stack file for option # 1, if I have one swarm cluster, this stack file should be able to deploy both portainer and the agent.
      Then if I want to manager more swarm clusters ( more SDLC environments), then I can use option # 2, can’t I?

      What would be the difference between option#2 and option# 3?

      Thanks,

      Reply


    • Option #1 is used to deploy both Portainer and the agent, option #2 can be used to deploy the agent only inside a Swarm cluster so that you can connect any existing Portainer instance to it and lastly option 3 can be used to deploy the agent on a standalone Docker host for remote management as well.

      Reply


Leave a comment!

All fields marked with an asterisk* are required.