Portainer Install

Want to learn how to setup portainer on your docker swarm? Read this info for more info

Portainer is a management solution for docker. Portainer allows you to easily manage your docker stacks, containers, services and more. This guide will teach you how to deploy portainer that is running behind traefikv2.

Requirements

Docker swarm installed and setup Traefik deployed

Installation:

Firstly we will need to create the folders that the data for portainer will be kept in. In my cluster I keep all my data in /var/data/servicename and my configs in /var/data/config/servicename But you can change this if you wish to store it somewhere else

mkdir -p /var/data/portainer mkdir -p /var/data/config/portainer

Now we will create portainer.yml

nano /var/data/config/portainer/portainer.yml

version: "3.4"

services:
  app:
    image: portainer/portainer-ce:latest
    volumes:
      - /var/data/portainer:/data
    ports:
      - 9002:9000
    networks:
      - traefik_public
      - internal
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.portainer.entrypoints=https"
        - "traefik.http.routers.portainer.rule=Host(`portainer.example.com`)"
        - "traefik.http.services.portainer.loadbalancer.server.port=9000"
      placement:
        constraints: [node.role == manager] 
    command: -H tcp://tasks.agent:9001 --tlsskipverify

  agent:
    image: portainer/agent
    environment:
      - AGENT_CLUSTER_ADDR=tasks.agent
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    ports:
      - target: 9001
        published: 9001
        protocol: tcp
        mode: host
    networks:
      - internal
    deploy:
      mode: global
      placement:
        constraints: [node.platform.os == linux]

networks:
  traefik_public:
    external: true
  internal:
    driver: overlay
    ipam:
      config:
        - subnet: 172.16.13.0/24

Once you have created portainer.yml and changed the host you can deploy the service using docker stack deploy portainer -c /var/data/config/portainer/portainer.yml.

When the service has been deployed successfully you will be able to access portainer via your host that you set in portainer.yml EG https://portainer.example.com and you will then be prompted to set your password. Once you have logged in you will be able to click Home and then “Primary” and you will now be able to manage your docker swarm


© 2020. All rights reserved.