Nethence Newdoc Olddoc Lab Your IP BBDock  

Docker Swarm

lately tested with Docker version 17.12.0-ce, build c97c6d6 on Ubuntu artful and Slackware 14.2


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

note. if there are multiple IP addresses configured you get a warning and need to specify on which one you want to advertise the service,

docker swarm init --advertise-addr x.x.x.x

generate the tokens,

#docker swarm join-token manager
docker swarm join-token worker

for the (manager or) workers to join the Swarm cluster,

ssh ceph@ceph1 docker swarm join --token x.x.x.x:2377

ssh ceph@ceph3 docker swarm join --token TOKEN x.x.x.x:2377

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

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

global mode without compose


replicas mode

to rebalance the instances after a host has recovered,

docker service ls
docker service update SERVICE-ID --detach=false --force


from the managers

to list the running instances and operating hosts,

docker stack ps appname

to remove an application,

docker stack rm appname

from the workers

for a worker to leave the cluster,

docker swarm leave

for a manager to leave the cluster,

docker swarm leave --force

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"
    # replace username/repo:tag with your name and image details
    image: pbraun9/ubuntu:latest
      replicas: 3
          cpus: "0.1"
          memory: 50M
        condition: on-failure
      - "8080:8080"
      - 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),

      - /datafs/weblab:/weblab

run the thing,

docker stack deploy -c docker-compose.yml appname

and check,

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


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


volume refs

other refs

Home | GitHub | Docker Hub | Donate | Contact