Nethence Newdoc Olddoc Lab Your IP BBDock  

setting up Docker Swarm & Compose

requirements

you need the Swarm nodes to be able to pull the image from a common repository.

init the Swarm cluster

as ceph@admin

I’m having 3 Ceph nodes sharing a common Ceph/FS into /datafs/. So let’s use ceph2 as Swarm manager and ceph1 and 3 as Swarm workers,

ssh ceph@ceph2
docker swarm init
#docker swarm join-tocken manager
docker swarm join-tocken worker
^D

ssh ceph@ceph1 docker swarm join --token WRK_TOKEN_HERE MANAGER_ADDRESS:2377
^D

ssh ceph@ceph3 docker swarm join --token WRK_TOKEN_HERE MANAGER_ADDRESS:2377
^D

Back to the manager node, check the Swarm cluster status,

ssh ceph@ceph2
docker node ls
docker node ps
docker node ps --no-trunc

prepare the Compose file

as ceph@ceph2

mkdir -p ~/compose/weblab/
cd ~/compose/weblab/
vi docker-compose.yml

here’s a basic example,

version: "3"
services:
  web:
    # replace username/repo:tag with your name and image details
    image: pbraun9/ubuntu:latest
    deploy:
      replicas: 3
      resources:
        limits:
          cpus: "0.1"
          memory: 50M
      restart_policy:
        condition: on-failure
    ports:
      - "8080:8080"
    networks:
      - webnet
networks:
  webnet:

and here’s how to create some depedencies – docker host constraints – among the containers.

bind/map a folder from the docker host

make sure the folder exists on the docker host,

mkdir /datafs/weblab/
echo ok > /datafs/weblab/test

then in the Compose service stanza (e.g. services / web),

    volumes:
      - /datafs/weblab:/weblab

run the thing,

docker stack deploy -c docker-compose.yml lab1

and check,

docker ps
docker exec -ti CONTAINER_NAME bash
ls -alhF /weblab/

operations

run the _webnet and _web containers and check on all the Swarm nodes at once,

docker stack deploy -c docker-compose.yml lab1
docker stack ps lab1

eventually change the number of replicas to scale the app,

vi docker-compose.yml
docker stack deploy -c docker-compose.yml lab1

review the services associated with the app,

docker stack services lab1

remove the containers,

docker stack rm lab1

refs

volume refs

other refs


Home | GitHub | Donate | Contact