Adding an Endpoint/Agent with Portainer

Jordan Lee
Jordan Lee
Adding an Endpoint/Agent with Portainer

Quick guide on adding endpoints to portainer without having your servers/clients in a swarm

So I have a main Linux server that is self hosted, and I have a few raspberry pi's as well. I wanted to be able to centrally manage everything from one place. One being managing Docker with Portainer and the other being managing servers in general with Cockpit. I know this is a bit overkill, but I like the learning process. So first I set out googling how to connect endpoints/agents to portainer. I kept seeing swarm come up. My devices aren't in a swarm cluster. I mean I could set up my Pi's in swarm but I just don't feel the need. With that being said I came across this article that pointed me in the right direction. However a few things are a bit different now, and this article wasn't exactly the clearest.

To start, let's get the endpoint set up on the device or server you want to add to your host. Mine being a raspberry pi running headless pi os, with docker and docker compose already installed. You can learn how to do all of that really quickly from here. And yes it is that easy lol.  

First lets make a directory for our docker compose file. I just called mine "pagent" for "portainer agent". You can name yours whatever it doesn't matter.

mkdir pagent

Next let's CD into that folder, and create a new docker compose document.

nano docker-compose.yml

In this document your going to enter the following. The port can be whatever you would like. If you are not sure how docker ports work or coded. The number to left of the colon is port that is attached to the host and the number to the right is the port connected to the container. If port 9001 is already in use on your host by something else you will need to change it.

version: '2'

  image: portainer/agent
  container_name: agent
    - 9001:9001
    - /var/run/docker.sock:/var/run/docker.sock
    - /var/lib/docker/volumes:/var/lib/docker/volumes
  restart: always

After you are done creating this .yml file you can run it by entering the following command within the directory of the file

docker-compose.yml up -d

Believe it or not. Your done on with the endpoint. Now over to your portainer interface.

In your portainer interface click on "Endpoints" in your left hand panel and the click "Add Endpoint"

Here you will enter whatever you would like to name this endpoint, I would recommend this to be what your device Hostname or DNS name is. Then enter the IP of that device followed by the port number that you have chosen to run the agent on. You can then add tags, or place this agent in a group. After this is completed you can simple click "Add Endpoint" at the bottom of the screen and your done.

Your newly added agent should show up at your "Homepage" or "Endpoints"  now.

Great! Next, complete checkout for full access to DevMug
Welcome back! You've successfully signed in
You've successfully subscribed to DevMug
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated