This assumes you already have a Portainer server set up and running. If not, you can set one up as such:

version: "3"
services:
  portainer:
    image: portainer/portainer-ce:latest
    ports:
      - 9443:9443
    volumes:
      - data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    restart: unless-stopped
volumes:
  data:

You can log into this portainer instance using https://<ip of server>:9443

Now lets say you have a remote docker environment you also want to monitor. Run this command on that docker environment to install the portainer agent: (Make sure port 9001 is accessible on this environment)

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:latest

Now back in your portainer UI, add a new environment:

portainer environments

And select Agent and fill in the name for your environment and enter the IP and port in the form ip_address:9001

portainer environments agent add

If you get an error such as “Host header not present” make sure you are using the same versions of portainer for the UI and the portainer agent and that the remote server doesn’t have an old image of the portainer agent. If it does, delete the old image so the new one can be downloaded.

When the agent is added, you will see this message:

environment created message

Back in your environments page in portainer you will see your new environment:

portainer main page
Categories: Docker