Skip to content

Instantly share code, notes, and snippets.

@punitganshani
Last active February 20, 2018 05:54
Show Gist options
  • Save punitganshani/2abb0e1e7bba8f715f09794785c9d5a8 to your computer and use it in GitHub Desktop.
Save punitganshani/2abb0e1e7bba8f715f09794785c9d5a8 to your computer and use it in GitHub Desktop.
PI Docker Swarm

Installing Docker on Raspberry PI

sudo apt-get upgrade
sudo apt-get update
curl -sSL https://get.docker.com | sh
sudo usermod -aG docker pi
sudo reboot

Pull image on Manager Node (192.168.1.28)

docker pull punitganshani/aspnet-docker-vote
  • This will download the image uploaded from Docker Cloud https://hub.docker.com/r/punitganshani/aspnet-docker-vote/
  • Source code is available on GitHub at https://github.com/punitganshani/aspnet-docker
  • This is a demo docker image running ASP.NET Core and Redis on Linux/AMD64
  • NOTE: ASP.NET Core does not run on ARM architecture so this is only for demonstrative purpose

Verify the images

pi@raspberrypi8:~ $  docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
punitganshani/aspnet-docker-vote   latest              624dbcbf152d        About an hour ago   307MB

Initialize Docker Swarm on Manager (192.168.1.28)

docker swarm init

Join Swarm as Worker (192.168.1.31)

docker swarm join --token SWMTKN-1-49s3x92tvy32hhavj7tv3n7wex8ai21rhi5tomnzg4zics8489-6s8e5xs6n5ygzk2cxcmok6m6s 192.168.1.28:2377

Join Swarm as Manager (192.168.1.29)

docker swarm join --token SWMTKN-1-49s3x92tvy32hhavj7tv3n7wex8ai21rhi5tomnzg4zics8489-4rkpiuxfx229uagyq802efar4 192.168.1.28:2377

Verify Swarm Configuration

docker info

The Manager node of the Swarm should have configuration like,

Swarm: active
 NodeID: ogf7mmqbqbb7k2inuevof8kqd
 Is Manager: true
 ClusterID: id85o247vxuafp398b524y253
 Managers: 2
 Nodes: 4
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 192.168.1.28
 Manager Addresses:
  192.168.1.28:2377
  192.168.1.29:2377

The Worker node of the Swarm should have configuration like,

Swarm: active
 NodeID: xuk2hpsth98zev8e3gn2nvs10
 Is Manager: false
 Node Address: 192.168.1.31
 Manager Addresses:
  192.168.1.28:2377
  192.168.1.29:2377

Create Docker Service on Manager 192.168.1.28

docker service create  punitganshani/aspnet-docker-vote

ASP.NET Core does not run on ARM architecture so this is only for demonstrative purpose

List services

pi@raspberrypi32:~ $ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                                     PORTS
wdvzhmcqso7n        gifted_wright       replicated          0/1                 punitganshani/aspnet-docker-vote:latest

Inspect Service (on Manager)

pi@raspberrypi32:~ $ docker service inspect wdvzhmcqso7n
[
    {
        "ID": "wdvzhmcqso7n4jk98kat3mdw6",
        "Version": {
            "Index": 109
        },
        "CreatedAt": "2018-02-20T03:42:45.149991398Z",
        "UpdatedAt": "2018-02-20T03:42:45.149991398Z",
        "Spec": {
            "Name": "gifted_wright",
            "Labels": {},
            "TaskTemplate": {
                "ContainerSpec": {
                    "Image": "punitganshani/aspnet-docker-vote:latest@sha256:cdd175470c58221523cfe9e0bf432fb70a3053bccb24697ac02eb68981e72215",
                    "StopGracePeriod": 10000000000,
                    "DNSConfig": {},
                    "Isolation": "default"
                },
                "Resources": {
                    "Limits": {},
                    "Reservations": {}
                },
                "RestartPolicy": {
                    "Condition": "any",
                    "Delay": 5000000000,
                    "MaxAttempts": 0
                },
                "Placement": {
                    "Platforms": [
                        {
                            "Architecture": "amd64",
                            "OS": "linux"
                        }
                    ]
                },
                "ForceUpdate": 0,
                "Runtime": "container"
            },
            "Mode": {
                "Replicated": {
                    "Replicas": 1
                }
            },
            "UpdateConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "RollbackConfig": {
                "Parallelism": 1,
                "FailureAction": "pause",
                "Monitor": 5000000000,
                "MaxFailureRatio": 0,
                "Order": "stop-first"
            },
            "EndpointSpec": {
                "Mode": "vip"
            }
        },
        "Endpoint": {
            "Spec": {}
        }
    }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment