/ Ansible

Docker Swarm using an old laptop

I'm using an old Samsung R580 laptop to create a docker swarm cluster of one. I plan on adding a couple of 1u servers to this later, as I can afford it. Once I'm done testing pfSense on the Asus EEE Netbook, I'll most likely bring it into the cluster as a backup until I'm able to add the 1u servers.

Docker has grown a lot over the past few years. During that time I have been seriously playing around with it and using it at work. Docker in swarm mode makes so many things possible quickly and simply. I'll go over the steps for installation and deployment of our docker swarm cluster of one and give some quick pointers and DOs and DONTs.

You will need

  • 1 to 1000+ physical hosts, vms, ec2 instances, or whatever will run docker.
  • A user with key authenticated ssh access and sudo privileges
  • I'm working with ubuntu 16.04, but docker works on many other platforms

Gaining some visualization into the cluster

You can easily manually check up on the health of your cluster from the command line with a few simple commands or perhaps corporate only needs a dashboard to look at and doesn't care for your nerdy commands.

docker service ls                                                                                     
ID                  NAME                MODE                REPLICAS            IMAGE                             PORTS
t9h59ml34qmh        viz_viz             replicated          1/1                 dockersamples/visualizer:latest   *:8080->8080/tcp

But sometimes it's nice to have a more visual display. This tool, docker visualiser is just what you need for such a task.

alt text

Here is a compose v3 stack file that should work for you

version: '3'

services:

  viz:
    image: dockersamples/visualizer
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
        - '8080:8080'
    deploy:
      replicas: 1

Save this to a file viz-stack.yml
and start it up.

docker stack deploy -c viz-stack.yml viz
Creating network viz_default
Creating service viz_viz

Check for the running service

docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                             PORTS
t9h59ml34qmh        viz_viz             replicated          1/1                 dockersamples/visualizer:latest   *:8080->8080/tcp

And finally, follow the log output

docker service logs -f viz_viz
[email protected]    | npm info it worked if it ends with ok
[email protected]    | npm info using [email protected]
[email protected]    | npm info using [email protected]
[email protected]    | npm info lifecycle [email protected]~prestart: [email protected]
[email protected]    | npm info lifecycle [email protected]~start: [email protected]
[email protected]    |
[email protected]    | > [email protected] start /app
[email protected]    | > node server.js
[email protected]    |

With that you should be able to browse to http://localhost:8080 and check it out.

ghost-stack.yml

ghost
Mounting a volume on the local machine at /data/ghost/content, for persistent data retention on a restart of the docker service.

version: '3'

services:

  blog:
    image: ghost:1-alpine
    volumes:
      - /data/ghost/content:/var/lib/ghost/content
    ports:
        - '2368:2368'
    deploy:
      replicas: 1

stress-stack.yml

For stress testing the system.

version: '3'

services:

  stress:
    image: progrium/stress
    command: '--cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 60s'
    deploy:
      replicas: 1
jahrik

jahrik

Self-taught, multilingual programmer, working in DevOps. Automating Linux server administration and deployment with the use of tools like Jenkins, Ansible, and Docker Swarm.

Read More
Docker Swarm using an old laptop
Share this

Subscribe to Homelab