Tue. Jan 18th, 2022

Let’s prepare to get started. This article assumes you have prepared your server for installation of Docker on a VM or Physical machine.

1 – sudo apt update
2 – sudo apt -y full-upgrade
Configure your hosts file for the cluster/swarm.

3 – sudo nano -c /etc/hosts <- update this with important server ips
127.0.0.1 localhost
127.0.1.1 poc01

xxx.xxx.xxx.xxx ohdoc01.cfs.loc ohdoc01
xxx.xxx.xxx.xxx ohdoc02.cfs.loc ohdoc02
xxx.xxx.xxx.xxx ohdoc03.cfs.loc ohdoc03
xxx.xxx.xxx.xxx ohdoc04.cfs.loc ohdoc04

Install Docker and Dependncies

4 – sudo apt -y install apache2-utils apt-transport-https ca-certificates curl gnupg2 software-properties-common
5 – sudo curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add –
6 – sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/debian buster stable”
7 – sudo htpasswd -nb admin secure_password <- Stor this in a safe place.
8 – cd /var/tmp
9 – sudo curl -fsSL https://get.docker.com -o get-docker.sh
10 – sudo chmod +x get-docker.sh
11 – sudo sh get-docker.sh
12 – sudo docker version

Install docker-compose so you can use it also

13 – sudo usermod -aG docker $USER
14 – sudo apt -y install docker-compose
16 – sudo docker-compose -version

Stop here if not building a swarm!

On the Master Node

18 – sudo mkdir -p projects/portainer
19 – sudo touch projects/portainer/agent-stack.yml <- Copy and past the text below in this file.

version: '3.2'

services:
  agent:
    image: portainer/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:
      - portainer_agent
    deploy:
      mode: global
      placement:
        constraints: [node.platform.os == linux]

networks:
  portainer_agent:
    driver: overlay
    attachable: true


20 – sudo nano -c projects/portainer/portainer-agent-stack.yml <- Copy and past the text below in this file.

version: '3.2'

services:
  agent:
    image: portainer/agent
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    networks:
      - agent_network
    deploy:
      mode: global
      placement:
        constraints: [node.platform.os == linux]

  portainer:
    image: portainer/portainer-ce:2.9.0
    command: -H tcp://tasks.agent:9001 --tlsskipverify
    ports:
      - "9000:9000"
      - "8000:8000"
    volumes:
      - portainer_data:/data
    networks:
      - agent_network
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.role == manager]

networks:
  agent_network:
    driver: overlay
    attachable: true

volumes:
  portainer_data:

DO NOT DO THIS UNTIL WORKER NODE IS DEPLOYED!

On the master node

21 – sudo docker swarm init

Do this one the master/leader node ONLY

22 – docker stack deploy -c agent-stack.yml portainer

On the worker node

docker swarm join –token <token info here>

Thank you for reading and if you need anything send your request via our contact page.

RPi Hobby Blog

By cfadmin

Leave a Reply

Your email address will not be published. Required fields are marked *